Juan Carlos Raña 14 years ago
parent
commit
12e5a8f669

+ 386 - 0
main/admin/add_courses_to_usergroup.php

@@ -0,0 +1,386 @@
+<?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).'usergroup.lib.php';
+
+$xajax = new xajax();
+
+//$xajax->debugOn();
+$xajax->registerFunction('search');
+
+// 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'));
+$interbreadcrumb[]=array('url' => 'usergroups.php','name' => get_lang('UserGroups'));
+
+// Database Table Definitions
+
+// setting the name of the tool
+$tool_name=get_lang('SubscribeSessionsToUserGroup');
+
+$add_type = 'multiple';
+if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){
+    $add_type = Security::remove_XSS($_REQUEST['add_type']);
+}
+
+$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
+$htmlHeadXtra[] = '
+<script type="text/javascript">
+function add_user_to_session (code, content) {
+
+    document.getElementById("user_to_add").value = "";
+    document.getElementById("ajax_list_users_single").innerHTML = "";
+
+    destination = document.getElementById("elements_in");
+
+    for (i=0;i<destination.length;i++) {
+        if(destination.options[i].text == content) {
+                return false;
+        }
+    }
+
+    destination.options[destination.length] = new Option(content,code);
+    destination.selectedIndex = -1;
+    sortOptions(destination.options);
+}
+function remove_item(origin) {
+    for(var i = 0 ; i<origin.options.length ; i++) {
+        if(origin.options[i].selected) {
+            origin.options[i]=null;
+            i = i-1;
+        }
+    }
+}
+
+function validate_filter() {
+        document.formulaire.add_type.value = \''.$add_type.'\';
+        document.formulaire.form_sent.value=0;
+        document.formulaire.submit();
+}
+</script>';
+
+
+$form_sent  = 0;
+$errorMsg   = '';
+$sessions=array();
+$usergroup = new UserGroup();
+$id = intval($_GET['id']);
+if($_POST['form_sent']) {
+    $form_sent              = $_POST['form_sent'];    
+    $elements_posted        = $_POST['elements_in_name'];     
+    if (!is_array($elements_posted)) {
+        $elements_posted=array();
+    }
+    if ($form_sent == 1) {
+        //added a parameter to send emails when registering a user        
+        $usergroup->subscribe_courses_to_usergroup($id, $elements_posted);
+        header('Location: usergroups.php');
+        exit;        
+    }
+}
+$data               = $usergroup->get($id);
+$course_list_in     = $usergroup->get_courses_by_usergroup($id);
+$course_list        = CourseManager::get_courses_list();
+
+//api_display_tool_title($tool_name.' ('.$session_info['name'].')');
+$elements_not_in = $elements_in= array();
+
+if (!empty($course_list)) {
+    foreach($course_list as $item) {        
+        if (in_array($item['id'], $course_list_in)) {            
+            $elements_in[$item['id']] = $item['title'];             
+        } else {
+            $elements_not_in[$item['id']] = $item['title'];
+        }
+    }
+}
+$ajax_search = $add_type == 'unique' ? true : false;
+
+//checking for extra field with filter on
+
+function search($needle,$type) {
+    global $tbl_user,$elements_in;
+    $xajax_response = new XajaxResponse();
+    $return = '';
+    if (!empty($needle) && !empty($type)) {
+
+        // xajax send utf8 datas... datas in db can be non-utf8 datas
+        $charset = api_get_system_encoding();
+        $needle  = Database::escape_string($needle);
+        $needle  = api_convert_encoding($needle, $charset, 'utf-8');
+
+        if ($type == 'single') {
+            // search users where username or firstname or lastname begins likes $needle
+          /*  $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
+                    WHERE (username LIKE "'.$needle.'%"
+                    OR firstname LIKE "'.$needle.'%"
+                OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'"   AND user.status<>'.DRH.''.
+                $order_clause.
+                ' LIMIT 11';*/
+        } else {
+            $list = CourseManager::get_courses_list(0, 0, 1, 'ASC', -1, $needle);
+        }     
+        $i=0;        
+        if ($type=='single') {
+            /*
+            while ($user = Database :: fetch_array($rs)) {
+                $i++;
+                if ($i<=10) {
+                    $person_name = api_get_person_name($user['firstname'], $user['lastname']);
+                    $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
+                } else {
+                    $return .= '...<br />';
+                }
+            }
+            $xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));*/
+        } else {
+            $return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">';
+            
+            foreach ($list as $row ) {         
+                if (!in_array($row['id'], array_keys($elements_in))) {       
+                    $return .= '<option value="'.$row['id'].'">'.$row['title'].'</option>';
+                }
+            }
+            $return .= '</select>';
+            $xajax_response -> addAssign('ajax_list_multiple','innerHTML',api_utf8_encode($return));
+        }
+    }
+    return $xajax_response;
+}
+$xajax -> processRequests();
+
+Display::display_header($tool_name);
+
+if ($add_type == 'multiple') {
+    $link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
+    $link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple');
+} else {
+    $link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique');
+    $link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
+}
+
+echo '<div class="actions">';
+echo '<a href="usergroups.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>';       
+echo '</div>';
+
+echo '<div class="row"><div class="form_header">'.$tool_name.' '.$data['name'].'</div></div><br/>'; ?>
+
+<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
+
+<?php
+if ($add_type=='multiple') {
+    if (is_array($extra_field_list)) {
+        if (is_array($new_field_list) && count($new_field_list)>0 ) {
+            echo '<h3>'.get_lang('FilterUsers').'</h3>';
+            foreach ($new_field_list as $new_field) {
+                echo $new_field['name'];
+                $varname = 'field_'.$new_field['variable'];
+                echo '&nbsp;<select name="'.$varname.'">';
+                echo '<option value="0">--'.get_lang('Select').'--</option>';
+                foreach ($new_field['data'] as $option) {
+                    $checked='';
+                    if (isset($_POST[$varname])) {
+                        if ($_POST[$varname]==$option[1]) {
+                            $checked = 'selected="true"';
+                        }
+                    }
+                    echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
+                }
+                echo '</select>';
+                echo '&nbsp;&nbsp;';
+            }
+            echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
+            echo '<br /><br />';
+        }
+    }
+}
+echo Display::input('hidden','id',$id);
+echo Display::input('hidden','form_sent','1');
+echo Display::input('hidden','add_type',null);
+if(!empty($errorMsg)) {
+    Display::display_normal_message($errorMsg); //main API
+}
+?>
+
+<table border="0" cellpadding="5" cellspacing="0" width="100%">
+<tr>
+  <td align="center"><b><?php echo get_lang('CoursesInPlatform') ?> :</b>
+  </td>
+  <td></td>
+  <td align="center"><b><?php echo get_lang('CoursesInGroup') ?> :</b></td>
+</tr>
+
+<?php if ($add_type=='multiple') { ?>
+<tr>
+<td align="center">
+<?php echo get_lang('FirstLetterSessions'); ?> :
+     <select name="firstLetterUser" onchange = "xajax_search(this.value,'multiple')" >
+      <option value = "%">--</option>
+      <?php
+        echo Display :: get_alphabet_options();
+      ?>
+     </select>
+</td>
+<td align="center">&nbsp;</td>
+</tr>
+<?php } ?>
+<tr>
+  <td align="center">
+  <div id="content_source">
+      <?php           
+      if (!($add_type=='multiple')) {        
+        ?>
+        <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
+        <div id="ajax_list_users_single"></div>
+        <?php
+      } else {               
+      ?>
+      <div id="ajax_list_multiple">
+        <?php echo Display::select('elements_not_in_name',$elements_not_in, '',array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?> 
+      </div>
+    <?php
+      }
+     ?>
+  </div>
+  </td>
+  <td width="10%" valign="middle" align="center">
+  <?php
+  if ($ajax_search) {
+  ?>
+    <button class="arrowl" type="button" onclick="remove_item(document.getElementById('elements_in'))" ></button>
+  <?php
+  } else {
+  ?>
+    <button class="arrowr" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))"></button>
+    <br /><br />
+    <button class="arrowl" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))"></button>
+    <?php
+  }
+  ?>
+    <br /><br /><br /><br /><br /><br />
+  </td>
+  <td align="center">
+<?php
+    echo Display::select('elements_in_name[]', $elements_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_in','size'=>'15px'),false );
+    unset($sessionUsersList);
+?>
+ </td>
+</tr>
+<tr>
+    <td colspan="3" align="center">
+        <br />
+        <?php
+        echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeCoursesToGroup').'</button>';
+        ?>
+    </td>
+</tr>
+</table>
+</form>
+
+<script type="text/javascript">
+<!--
+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('elements_in').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('elements_not_in'));
+    sessionUsers = makepost(document.getElementById('elements_in'));
+    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();

+ 63 - 234
main/admin/add_sessions_to_promotion.php

@@ -42,109 +42,6 @@ if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){
     $add_type = Security::remove_XSS($_REQUEST['add_type']);
 }
 
-//checking for extra field with filter on
-
-function search_sessions($needle,$type) {
-    global $tbl_user,$tbl_session_rel_user,$id_session;
-    $xajax_response = new XajaxResponse();
-    $return = '';
-
-    if (!empty($needle) && !empty($type)) {
-
-        // xajax send utf8 datas... datas in db can be non-utf8 datas
-        $charset = api_get_system_encoding();
-        $needle = Database::escape_string($needle);
-        $needle = api_convert_encoding($needle, $charset, 'utf-8');
-        $user_anonymous=api_get_anonymous_id();
-
-        $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
-        $cond_user_id = '';
-        if (!empty($id_session)) {
-        $id_session = Database::escape_string($id_session);
-            // check id_user from session_rel_user table
-            $sql = 'SELECT id_user FROM '.$tbl_session_rel_user.' WHERE id_session ="'.(int)$id_session.'" AND relation_type<>'.SESSION_RELATION_TYPE_RRHH.' ';
-            $res = Database::query($sql);
-            $user_ids = array();
-            if (Database::num_rows($res) > 0) {
-                while ($row = Database::fetch_row($res)) {
-                    $user_ids[] = (int)$row[0];
-                }
-            }
-            if (count($user_ids) > 0){
-                $cond_user_id = ' AND user.user_id NOT IN('.implode(",",$user_ids).')';
-            }
-        }
-
-        if ($type == 'single') {
-            // search users where username or firstname or lastname begins likes $needle
-            $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
-                    WHERE (username LIKE "'.$needle.'%"
-                    OR firstname LIKE "'.$needle.'%"
-                OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'"   AND user.status<>'.DRH.''.
-                $order_clause.
-                ' LIMIT 11';
-        } else {
-            $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
-                    WHERE '.(api_sort_by_first_name() ? 'firstname' : 'lastname').' LIKE "'.$needle.'%" AND user.status<>'.DRH.' AND user.user_id<>"'.$user_anonymous.'"'.$cond_user_id.
-                    $order_clause;
-        }
-
-        global $_configuration;
-        if ($_configuration['multiple_access_urls']) {
-            $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-            $access_url_id = api_get_current_access_url_id();
-            if ($access_url_id != -1){
-                if ($type == 'single') {
-                    $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
-                    INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
-                    WHERE access_url_id = '.$access_url_id.'  AND (username LIKE "'.$needle.'%"
-                    OR firstname LIKE "'.$needle.'%"
-                    OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'" AND user.status<>'.DRH.' '.
-                    $order_clause.
-                    ' LIMIT 11';
-                } else {
-                    $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
-                    INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
-                    WHERE access_url_id = '.$access_url_id.'
-                    AND '.(api_sort_by_first_name() ? 'firstname' : 'lastname').' LIKE "'.$needle.'%" AND user.status<>'.DRH.' AND user.user_id<>"'.$user_anonymous.'"'.$cond_user_id.
-                    $order_clause;
-                }
-
-            }
-        }
-
-        $rs = Database::query($sql);
-        $i=0;
-        if ($type=='single') {
-            while ($user = Database :: fetch_array($rs)) {
-                $i++;
-                if ($i<=10) {
-                    $person_name = api_get_person_name($user['firstname'], $user['lastname']);
-                    $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
-                } else {
-                    $return .= '...<br />';
-                }
-            }
-
-            $xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));
-
-        } else {
-            global $nosessionUsersList;
-            $return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
-            while ($user = Database :: fetch_array($rs)) {
-                $person_name = api_get_person_name($user['firstname'], $user['lastname']);
-                $return .= '<option value="'.$user['user_id'].'">'.$person_name.' ('.$user['username'].')</option>';
-            }
-            $return .= '</select>';
-            $xajax_response -> addAssign('ajax_list_users_multiple','innerHTML',api_utf8_encode($return));
-        }
-    }
-
-    return $xajax_response;
-}
-
-$xajax -> processRequests();
-
 $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
 $htmlHeadXtra[] = '
 <script type="text/javascript">
@@ -182,19 +79,13 @@ function validate_filter() {
 </script>';
 
 
-$form_sent=0;
-$errorMsg=$firstLetterUser=$firstLetterSession='';
-$UserList=$SessionList=array();
-$users=$sessions=array();
-$noPHP_SELF=true;
-
+$form_sent  = 0;
+$errorMsg   = '';
+$users      =$sessions=array();
 $promotion = new Promotion();
 $id = intval($_GET['id']);
-//echo '<pre>';
 if($_POST['form_sent']) {
-    $form_sent          = $_POST['form_sent'];
-    $firstLetterUser    = $_POST['firstLetterUser'];
-    $firstLetterSession = $_POST['firstLetterSession'];
+    $form_sent          = $_POST['form_sent'];    
     $session_in_promotion_posted       = $_POST['session_in_promotion_name'];     
     if (!is_array($session_in_promotion_posted)) {
         $session_in_promotion_posted=array();
@@ -207,10 +98,8 @@ if($_POST['form_sent']) {
     }
 }
 
-Display::display_header($tool_name);
-
 $promotion_data = $promotion->get($id);
-$session_list = SessionManager::get_sessions_list();
+$session_list   = SessionManager::get_sessions_list(array(), array('name'));
 
 //api_display_tool_title($tool_name.' ('.$session_info['name'].')');
 $session_not_in_promotion = $session_in_promotion= array();
@@ -222,117 +111,68 @@ if (!empty($session_list)) {
             if ($promotion_id == $id) {                
                 $session_in_promotion[$session['id']] = $session['name'];
             } else {
-            	$session_not_in_promotion[$session['id']] = $session['name'];
+                $session_not_in_promotion[$session['id']] = $session['name'];
             } 
         } else {
-        	$session_not_in_promotion[$session['id']] = $session['name'];
+            $session_not_in_promotion[$session['id']] = $session['name'];
         }
     }
 }
 $ajax_search = $add_type == 'unique' ? true : false;
 
-if ($ajax_search) {
-    $sql="SELECT user_id, lastname, firstname, username, id_session
-            FROM $tbl_user
-            INNER JOIN $tbl_session_rel_user
-                ON $tbl_session_rel_user.id_user = $tbl_user.user_id AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-                AND $tbl_session_rel_user.id_session = ".intval($id_session)."
-                WHERE status<>".DRH." $order_clause";
-
-    if ($_configuration['multiple_access_urls']) {
-        $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-        $access_url_id = api_get_current_access_url_id();
-        if ($access_url_id != -1){
-            $sql="SELECT u.user_id, lastname, firstname, username, id_session
-            FROM $tbl_user u
-            INNER JOIN $tbl_session_rel_user
-                ON $tbl_session_rel_user.id_user = u.user_id AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-                AND $tbl_session_rel_user.id_session = ".intval($id_session)."
-                INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
-                WHERE access_url_id = $access_url_id AND u.status<>".DRH."
-                $order_clause";
-        }
-    }
-    $result=Database::query($sql);
-    $users=Database::store_result($result);
-    foreach ($users as $user) {
-        $sessionUsersList[$user['user_id']] = $user ;
-    }
-} else {
-          $sql="SELECT  user_id, lastname, firstname, username, id_session
-            FROM $tbl_user u
-            LEFT JOIN $tbl_session_rel_user
-            ON $tbl_session_rel_user.id_user = u.user_id AND $tbl_session_rel_user.id_session = '$id_session' AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-            WHERE u.status<>".DRH."
-        $order_clause";
-       
-        if ($_configuration['multiple_access_urls']) {
-            $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-            $access_url_id = api_get_current_access_url_id();
-            if ($access_url_id != -1){
-                $sql="SELECT  u.user_id, lastname, firstname, username, id_session
-                FROM $tbl_user u
-                LEFT JOIN $tbl_session_rel_user
-                    ON $tbl_session_rel_user.id_user = u.user_id AND $tbl_session_rel_user.id_session = '$id_session' AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-                INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
-                WHERE access_url_id = $access_url_id  $where_filter AND u.status<>".DRH."
-            $order_clause";
-            }
-        }
+//checking for extra field with filter on
 
-        $result=Database::query($sql);
-        $users=Database::store_result($result);
-        //var_dump($_REQUEST['id_session']);
-        foreach ($users as $user) {
-            if($user['id_session'] != $id_session)
-                $nosessionUsersList[$user['user_id']] = $user ;
-        }
-        $user_anonymous=api_get_anonymous_id();
-        if (count($nosessionUsersList) > 0) {
-            foreach($nosessionUsersList as $key_user_list =>$value_user_list) {
-                if ($nosessionUsersList[$key_user_list]['user_id']==$user_anonymous) {
-                    unset($nosessionUsersList[$key_user_list]);
+function search_sessions($needle,$type) {
+    global $tbl_user,$session_in_promotion;
+    $xajax_response = new XajaxResponse();
+    $return = '';
+    if (!empty($needle) && !empty($type)) {
+
+        // xajax send utf8 datas... datas in db can be non-utf8 datas
+        $charset = api_get_system_encoding();
+        $needle = Database::escape_string($needle);
+        $needle = api_convert_encoding($needle, $charset, 'utf-8');
+
+        if ($type == 'single') {
+            // search users where username or firstname or lastname begins likes $needle
+          /*  $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
+                    WHERE (username LIKE "'.$needle.'%"
+                    OR firstname LIKE "'.$needle.'%"
+                OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'"   AND user.status<>'.DRH.''.
+                $order_clause.
+                ' LIMIT 11';*/
+        } else {
+            $session_list = SessionManager::get_sessions_list(array('s.name LIKE' => "$needle%"));
+        }     
+        $i=0;        
+        if ($type=='single') {
+            /*
+            while ($user = Database :: fetch_array($rs)) {
+                $i++;
+                if ($i<=10) {
+                    $person_name = api_get_person_name($user['firstname'], $user['lastname']);
+                    $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
+                } else {
+                    $return .= '...<br />';
                 }
             }
-        }
-        //filling the correct users in list
-        $sql="SELECT  user_id, lastname, firstname, username, id_session
-            FROM $tbl_user u
-            LEFT JOIN $tbl_session_rel_user
-            ON $tbl_session_rel_user.id_user = u.user_id AND $tbl_session_rel_user.id_session = '$id_session' AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-            WHERE u.status<>".DRH." $order_clause";
-
-        if ($_configuration['multiple_access_urls']) {
-            $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-            $access_url_id = api_get_current_access_url_id();
-            if ($access_url_id != -1){
-                $sql="SELECT  u.user_id, lastname, firstname, username, id_session
-                FROM $tbl_user u
-                LEFT JOIN $tbl_session_rel_user
-                    ON $tbl_session_rel_user.id_user = u.user_id AND $tbl_session_rel_user.id_session = '$id_session' AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-                INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
-                WHERE access_url_id = $access_url_id AND u.status<>".DRH."
-                $order_clause";
-            }
-        }
-    $result=Database::query($sql);
-    $users=Database::store_result($result);
-
-    foreach($users as $key_user_list =>$value_user_list) {
-        if ($users[$key_user_list]['user_id']==$user_anonymous) {
-            unset($users[$key_user_list]);
+            $xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));*/
+        } else {
+            $return .= '<select id="session_not_in_promotion" name="session_not_in_promotion_name[]" multiple="multiple" size="15" style="width:360px;">';            
+            foreach ($session_list as $row ) {         
+                if (!in_array($row['id'], array_keys($session_in_promotion))) {       
+                    $return .= '<option value="'.$row['id'].'">'.$row['name'].'</option>';
+                }
             }
+            $return .= '</select>';
+            $xajax_response -> addAssign('ajax_list_multiple','innerHTML',api_utf8_encode($return));
         }
-
-    foreach ($users as $user) {
-        if($user['id_session'] == $id_session){
-            $sessionUsersList[$user['user_id']] = $user;
-            if (array_key_exists($user['user_id'],$nosessionUsersList))
-                unset($nosessionUsersList[$user['user_id']]);
-        }
-
     }
+    return $xajax_response;
 }
+$xajax -> processRequests();
+
+Display::display_header($tool_name);
 
 if ($add_type == 'multiple') {
     $link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
@@ -341,15 +181,12 @@ if ($add_type == 'multiple') {
     $link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique');
     $link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
 }
-/*
-<div class="actions">
-    <?php echo $link_add_type_unique ?>&nbsp;|&nbsp;<?php echo $link_add_type_multiple ?>
-</div>
-*/
-?>
 
+echo '<div class="actions">';
+echo '<a href="promotions.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>';       
+echo '</div>';
 
-<?php echo '<div class="row"><div class="form_header">'.$tool_name.' '.$promotion_data['name'].'</div></div><br/>'; ?>
+echo '<div class="row"><div class="form_header">'.$tool_name.' '.$promotion_data['name'].'</div></div><br/>'; ?>
 
 <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
 
@@ -389,7 +226,6 @@ if(!empty($errorMsg)) {
 ?>
 
 <table border="0" cellpadding="5" cellspacing="0" width="100%">
-<!-- Users -->
 <tr>
   <td align="center"><b><?php echo get_lang('SessionsInPlatform') ?> :</b>
   </td>
@@ -400,7 +236,6 @@ if(!empty($errorMsg)) {
 <?php if ($add_type=='multiple') { ?>
 <tr>
 <td align="center">
-
 <?php echo get_lang('FirstLetterSessions'); ?> :
      <select name="firstLetterUser" onchange = "xajax_search_sessions(this.value,'multiple')" >
       <option value = "%">--</option>
@@ -415,23 +250,19 @@ if(!empty($errorMsg)) {
 <tr>
   <td align="center">
   <div id="content_source">
-      <?php
-      
-      
-      if (!($add_type=='multiple')) {
+      <?php           
+      if (!($add_type=='multiple')) {        
         ?>
         <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
         <div id="ajax_list_users_single"></div>
         <?php
-      } else {        
-        echo Display::select('session_not_in_promotion_name',$session_not_in_promotion, '',array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'session_not_in_promotion','size'=>'15px'),false);
+      } else {               
       ?>
-      <div id="ajax_list_users_multiple">
-        
+      <div id="ajax_list_multiple">
+        <?php echo Display::select('session_not_in_promotion_name',$session_not_in_promotion, '',array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'session_not_in_promotion','size'=>'15px'),false); ?> 
       </div>
     <?php
       }
-      unset($nosessionUsersList);
      ?>
   </div>
   </td>
@@ -453,7 +284,6 @@ if(!empty($errorMsg)) {
   </td>
   <td align="center">
 <?php
-
     echo Display::select('session_in_promotion_name[]', $session_in_promotion, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'session_in_promotion','size'=>'15px'),false );
     unset($sessionUsersList);
 ?>
@@ -559,7 +389,6 @@ function makepost(select){
 
 }
 -->
-
 </script>
 <?php
-Display::display_footer();
+Display::display_footer();

+ 388 - 0
main/admin/add_sessions_to_usergroup.php

@@ -0,0 +1,388 @@
+<?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).'usergroup.lib.php';
+require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
+
+$xajax = new xajax();
+
+//$xajax->debugOn();
+$xajax->registerFunction('search_sessions');
+
+// 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'));
+$interbreadcrumb[]=array('url' => 'usergroups.php','name' => get_lang('UserGroups'));
+
+// Database Table Definitions
+
+// setting the name of the tool
+$tool_name=get_lang('SubscribeSessionsToUserGroup');
+
+$add_type = 'multiple';
+if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){
+    $add_type = Security::remove_XSS($_REQUEST['add_type']);
+}
+
+$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
+$htmlHeadXtra[] = '
+<script type="text/javascript">
+function add_user_to_session (code, content) {
+
+    document.getElementById("user_to_add").value = "";
+    document.getElementById("ajax_list_users_single").innerHTML = "";
+
+    destination = document.getElementById("elements_in");
+
+    for (i=0;i<destination.length;i++) {
+        if(destination.options[i].text == content) {
+                return false;
+        }
+    }
+
+    destination.options[destination.length] = new Option(content,code);
+    destination.selectedIndex = -1;
+    sortOptions(destination.options);
+}
+function remove_item(origin) {
+    for(var i = 0 ; i<origin.options.length ; i++) {
+        if(origin.options[i].selected) {
+            origin.options[i]=null;
+            i = i-1;
+        }
+    }
+}
+
+function validate_filter() {
+        document.formulaire.add_type.value = \''.$add_type.'\';
+        document.formulaire.form_sent.value=0;
+        document.formulaire.submit();
+}
+</script>';
+
+
+$form_sent  = 0;
+$errorMsg   = '';
+$sessions=array();
+$usergroup = new UserGroup();
+$id = intval($_GET['id']);
+if($_POST['form_sent']) {
+    $form_sent          = $_POST['form_sent'];    
+    $elements_posted    = $_POST['elements_in_name'];     
+    if (!is_array($elements_posted)) {
+        $elements_posted = array();
+    }
+    if ($form_sent == 1) {
+        //added a parameter to send emails when registering a user        
+        $usergroup->subscribe_sessions_to_usergroup($id, $elements_posted);
+        header('Location: usergroups.php');
+        exit;        
+    }
+}
+$data               = $usergroup->get($id);
+$session_list_in    = $usergroup->get_sessions_by_usergroup($id);
+$session_list       = SessionManager::get_sessions_list(array(), array('name'));
+
+//api_display_tool_title($tool_name.' ('.$session_info['name'].')');
+$elements_not_in = $elements_in= array();
+
+if (!empty($session_list)) {
+    foreach($session_list as $session) {        
+        if (in_array($session['id'], $session_list_in)) {            
+            $elements_in[$session['id']] = $session['name'];             
+        } else {
+            $elements_not_in[$session['id']] = $session['name'];
+        }
+    }
+}
+
+$ajax_search = $add_type == 'unique' ? true : false;
+
+//checking for extra field with filter on
+
+function search_sessions($needle,$type) {
+    global $tbl_user,$elements_in;
+    $xajax_response = new XajaxResponse();
+    $return = '';
+    if (!empty($needle) && !empty($type)) {
+
+        // xajax send utf8 datas... datas in db can be non-utf8 datas
+        $charset = api_get_system_encoding();
+        $needle  = Database::escape_string($needle);
+        $needle  = api_convert_encoding($needle, $charset, 'utf-8');
+
+        if ($type == 'single') {
+            // search users where username or firstname or lastname begins likes $needle
+          /*  $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
+                    WHERE (username LIKE "'.$needle.'%"
+                    OR firstname LIKE "'.$needle.'%"
+                OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'"   AND user.status<>'.DRH.''.
+                $order_clause.
+                ' LIMIT 11';*/
+        } else {
+            $session_list = SessionManager::get_sessions_list(array('s.name LIKE' => "$needle%"));
+        }     
+        $i=0;        
+        if ($type=='single') {
+            /*
+            while ($user = Database :: fetch_array($rs)) {
+                $i++;
+                if ($i<=10) {
+                    $person_name = api_get_person_name($user['firstname'], $user['lastname']);
+                    $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
+                } else {
+                    $return .= '...<br />';
+                }
+            }
+            $xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));*/
+        } else {
+            $return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">';
+            
+            foreach ($session_list as $row ) {         
+                if (!in_array($row['id'], array_keys($elements_in))) {       
+                    $return .= '<option value="'.$row['id'].'">'.$row['name'].'</option>';
+                }
+            }
+            $return .= '</select>';
+            $xajax_response -> addAssign('ajax_list_multiple','innerHTML',api_utf8_encode($return));
+        }
+    }
+    return $xajax_response;
+}
+$xajax -> processRequests();
+
+Display::display_header($tool_name);
+
+if ($add_type == 'multiple') {
+    $link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
+    $link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple');
+} else {
+    $link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique');
+    $link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
+}
+
+echo '<div class="actions">';
+echo '<a href="usergroups.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>';       
+echo '</div>';
+
+echo '<div class="row"><div class="form_header">'.$tool_name.' '.$data['name'].'</div></div><br/>'; ?>
+
+<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
+
+<?php
+if ($add_type=='multiple') {
+    if (is_array($extra_field_list)) {
+        if (is_array($new_field_list) && count($new_field_list)>0 ) {
+            echo '<h3>'.get_lang('FilterUsers').'</h3>';
+            foreach ($new_field_list as $new_field) {
+                echo $new_field['name'];
+                $varname = 'field_'.$new_field['variable'];
+                echo '&nbsp;<select name="'.$varname.'">';
+                echo '<option value="0">--'.get_lang('Select').'--</option>';
+                foreach ($new_field['data'] as $option) {
+                    $checked='';
+                    if (isset($_POST[$varname])) {
+                        if ($_POST[$varname]==$option[1]) {
+                            $checked = 'selected="true"';
+                        }
+                    }
+                    echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
+                }
+                echo '</select>';
+                echo '&nbsp;&nbsp;';
+            }
+            echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
+            echo '<br /><br />';
+        }
+    }
+}
+echo Display::input('hidden','id',$id);
+echo Display::input('hidden','form_sent','1');
+echo Display::input('hidden','add_type',null);
+if(!empty($errorMsg)) {
+    Display::display_normal_message($errorMsg); //main API
+}
+?>
+
+<table border="0" cellpadding="5" cellspacing="0" width="100%">
+<tr>
+  <td align="center"><b><?php echo get_lang('SessionsInPlatform') ?> :</b>
+  </td>
+  <td></td>
+  <td align="center"><b><?php echo get_lang('SessionsInGroup') ?> :</b></td>
+</tr>
+
+<?php if ($add_type=='multiple') { ?>
+<tr>
+<td align="center">
+<?php echo get_lang('FirstLetterSessions'); ?> :
+     <select name="firstLetterUser" onchange = "xajax_search_sessions(this.value,'multiple')" >
+      <option value = "%">--</option>
+      <?php
+        echo Display :: get_alphabet_options();
+      ?>
+     </select>
+</td>
+<td align="center">&nbsp;</td>
+</tr>
+<?php } ?>
+<tr>
+  <td align="center">
+  <div id="content_source">
+      <?php           
+      if (!($add_type=='multiple')) {        
+        ?>
+        <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
+        <div id="ajax_list_users_single"></div>
+        <?php
+      } else {               
+      ?>
+      <div id="ajax_list_multiple">
+        <?php echo Display::select('elements_not_in_name',$elements_not_in, '',array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?> 
+      </div>
+    <?php
+      }
+     ?>
+  </div>
+  </td>
+  <td width="10%" valign="middle" align="center">
+  <?php
+  if ($ajax_search) {
+  ?>
+    <button class="arrowl" type="button" onclick="remove_item(document.getElementById('elements_in'))" ></button>
+  <?php
+  } else {
+  ?>
+    <button class="arrowr" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))"></button>
+    <br /><br />
+    <button class="arrowl" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))"></button>
+    <?php
+  }
+  ?>
+    <br /><br /><br /><br /><br /><br />
+  </td>
+  <td align="center">
+<?php
+    echo Display::select('elements_in_name[]', $elements_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_in','size'=>'15px'),false );
+    unset($sessionUsersList);
+?>
+ </td>
+</tr>
+<tr>
+    <td colspan="3" align="center">
+        <br />
+        <?php
+        echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeSessionsToGroup').'</button>';
+        ?>
+    </td>
+</tr>
+</table>
+</form>
+
+<script type="text/javascript">
+<!--
+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('elements_in').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('elements_not_in'));
+    sessionUsers = makepost(document.getElementById('elements_in'));
+    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();

+ 391 - 0
main/admin/add_users_to_usergroup.php

@@ -0,0 +1,391 @@
+<?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).'usergroup.lib.php';
+require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
+
+$xajax = new xajax();
+
+//$xajax->debugOn();
+$xajax->registerFunction('search');
+
+// 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'));
+$interbreadcrumb[]=array('url' => 'usergroups.php','name' => get_lang('UserGroups'));
+
+// Database Table Definitions
+
+// setting the name of the tool
+$tool_name=get_lang('SubscribeUsersToUserGroup');
+
+$add_type = 'multiple';
+if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){
+    $add_type = Security::remove_XSS($_REQUEST['add_type']);
+}
+
+$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
+$htmlHeadXtra[] = '
+<script type="text/javascript">
+function add_user_to_session (code, content) {
+
+    document.getElementById("user_to_add").value = "";
+    document.getElementById("ajax_list_users_single").innerHTML = "";
+
+    destination = document.getElementById("elements_in");
+
+    for (i=0;i<destination.length;i++) {
+        if(destination.options[i].text == content) {
+                return false;
+        }
+    }
+
+    destination.options[destination.length] = new Option(content,code);
+    destination.selectedIndex = -1;
+    sortOptions(destination.options);
+}
+function remove_item(origin) {
+    for(var i = 0 ; i<origin.options.length ; i++) {
+        if(origin.options[i].selected) {
+            origin.options[i]=null;
+            i = i-1;
+        }
+    }
+}
+
+function validate_filter() {
+        document.formulaire.add_type.value = \''.$add_type.'\';
+        document.formulaire.form_sent.value=0;
+        document.formulaire.submit();
+}
+</script>';
+
+
+$form_sent  = 0;
+$errorMsg   = '';
+$sessions=array();
+$usergroup = new UserGroup();
+$id = intval($_GET['id']);
+if($_POST['form_sent']) {
+    $form_sent              = $_POST['form_sent'];    
+    $elements_posted        = $_POST['elements_in_name'];     
+    if (!is_array($elements_posted)) {
+        $elements_posted=array();
+    }
+    if ($form_sent == 1) {
+        //added a parameter to send emails when registering a user        
+        $usergroup->subscribe_users_to_usergroup($id, $elements_posted);
+        header('Location: usergroups.php');
+        exit;        
+    }
+}
+$data       = $usergroup->get($id);
+$list_in    = $usergroup->get_users_by_usergroup($id);
+$user_list  = UserManager::get_user_list();
+
+//api_display_tool_title($tool_name.' ('.$session_info['name'].')');
+$elements_not_in = $elements_in = array();
+
+if (!empty($user_list)) {
+    foreach($user_list as $item) {
+        $person_name = api_get_person_name($item['firstname'], $item['lastname']);        
+        if (in_array($item['user_id'], $list_in)) {                        
+            $elements_in[$item['user_id']] = $person_name;             
+        } else {
+            $elements_not_in[$item['user_id']] = $person_name;
+        }
+    }
+}
+
+
+$ajax_search = $add_type == 'unique' ? true : false;
+
+//checking for extra field with filter on
+
+function search($needle,$type) {
+    global $tbl_user,$elements_in;
+    $xajax_response = new XajaxResponse();
+    $return = '';
+    if (!empty($needle) && !empty($type)) {
+
+        // xajax send utf8 datas... datas in db can be non-utf8 datas
+        $charset = api_get_system_encoding();
+        $needle  = Database::escape_string($needle);
+        $needle  = api_convert_encoding($needle, $charset, 'utf-8');
+
+        if ($type == 'single') {
+            // search users where username or firstname or lastname begins likes $needle
+          /*  $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
+                    WHERE (username LIKE "'.$needle.'%"
+                    OR firstname LIKE "'.$needle.'%"
+                OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'"   AND user.status<>'.DRH.''.
+                $order_clause.
+                ' LIMIT 11';*/
+        } else {
+            $list = UserManager::get_user_list_like(array('firstname'=>$needle));
+        }     
+        $i=0;        
+        if ($type=='single') {
+            /*
+            while ($user = Database :: fetch_array($rs)) {
+                $i++;
+                if ($i<=10) {
+                    $person_name = api_get_person_name($user['firstname'], $user['lastname']);
+                    $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
+                } else {
+                    $return .= '...<br />';
+                }
+            }
+            $xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));*/
+        } else {
+            $return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">';
+            
+            foreach ($list as $item ) {         
+                if (!in_array($item['user_id'], array_keys($elements_in))) {       
+                    $person_name = api_get_person_name($item['firstname'], $item['lastname']);   
+                    $return .= '<option value="'.$item['user_id'].'">'.$person_name.'</option>';
+                }
+            }
+            $return .= '</select>';
+            $xajax_response -> addAssign('ajax_list_multiple','innerHTML',api_utf8_encode($return));
+        }
+    }
+    return $xajax_response;
+}
+$xajax -> processRequests();
+
+Display::display_header($tool_name);
+
+if ($add_type == 'multiple') {
+    $link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
+    $link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple');
+} else {
+    $link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique');
+    $link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
+}
+
+echo '<div class="actions">';
+echo '<a href="usergroups.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>';       
+echo '</div>';
+
+echo '<div class="row"><div class="form_header">'.$tool_name.' '.$data['name'].'</div></div><br/>'; ?>
+
+<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
+
+<?php
+if ($add_type=='multiple') {
+    if (is_array($extra_field_list)) {
+        if (is_array($new_field_list) && count($new_field_list)>0 ) {
+            echo '<h3>'.get_lang('FilterUsers').'</h3>';
+            foreach ($new_field_list as $new_field) {
+                echo $new_field['name'];
+                $varname = 'field_'.$new_field['variable'];
+                echo '&nbsp;<select name="'.$varname.'">';
+                echo '<option value="0">--'.get_lang('Select').'--</option>';
+                foreach ($new_field['data'] as $option) {
+                    $checked='';
+                    if (isset($_POST[$varname])) {
+                        if ($_POST[$varname]==$option[1]) {
+                            $checked = 'selected="true"';
+                        }
+                    }
+                    echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
+                }
+                echo '</select>';
+                echo '&nbsp;&nbsp;';
+            }
+            echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
+            echo '<br /><br />';
+        }
+    }
+}
+echo Display::input('hidden','id',$id);
+echo Display::input('hidden','form_sent','1');
+echo Display::input('hidden','add_type',null);
+if(!empty($errorMsg)) {
+    Display::display_normal_message($errorMsg); //main API
+}
+?>
+
+<table border="0" cellpadding="5" cellspacing="0" width="100%">
+<tr>
+  <td align="center"><b><?php echo get_lang('SessionsInPlatform') ?> :</b>
+  </td>
+  <td></td>
+  <td align="center"><b><?php echo get_lang('SessionsInGroup') ?> :</b></td>
+</tr>
+
+<?php if ($add_type=='multiple') { ?>
+<tr>
+<td align="center">
+<?php echo get_lang('FirstLetterSessions'); ?> :
+     <select name="firstLetterUser" onchange = "xajax_search(this.value,'multiple')" >
+      <option value = "%">--</option>
+      <?php
+        echo Display :: get_alphabet_options();
+      ?>
+     </select>
+</td>
+<td align="center">&nbsp;</td>
+</tr>
+<?php } ?>
+<tr>
+  <td align="center">
+  <div id="content_source">
+      <?php           
+      if (!($add_type=='multiple')) {        
+        ?>
+        <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
+        <div id="ajax_list_users_single"></div>
+        <?php
+      } else {               
+      ?>
+      <div id="ajax_list_multiple">
+        <?php echo Display::select('elements_not_in_name',$elements_not_in, '',array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?> 
+      </div>
+    <?php
+      }
+     ?>
+  </div>
+  </td>
+  <td width="10%" valign="middle" align="center">
+  <?php
+  if ($ajax_search) {
+  ?>
+    <button class="arrowl" type="button" onclick="remove_item(document.getElementById('elements_in'))" ></button>
+  <?php
+  } else {
+  ?>
+    <button class="arrowr" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))"></button>
+    <br /><br />
+    <button class="arrowl" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))"></button>
+    <?php
+  }
+  ?>
+    <br /><br /><br /><br /><br /><br />
+  </td>
+  <td align="center">
+<?php
+    echo Display::select('elements_in_name[]', $elements_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_in','size'=>'15px'),false );
+    unset($sessionUsersList);
+?>
+ </td>
+</tr>
+<tr>
+    <td colspan="3" align="center">
+        <br />
+        <?php
+        echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeUsersToGroup').'</button>';
+        ?>
+    </td>
+</tr>
+</table>
+</form>
+
+<script type="text/javascript">
+<!--
+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('elements_in').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('elements_not_in'));
+    sessionUsers = makepost(document.getElementById('elements_in'));
+    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();

+ 17 - 17
main/admin/class_add.php

@@ -2,25 +2,25 @@
 // $Id: class_add.php 10215 2006-11-27 13:57:17Z pcool $
 /*
 ==============================================================================
-	Dokeos - elearning and course management software
+    Dokeos - elearning and course management software
 
-	Copyright (c) 2004 Dokeos S.A.
-	Copyright (c) 2003 Ghent University (UGent)
-	Copyright (c) 2001 Universite catholique de Louvain (UCL)
-	Copyright (c) Olivier Brouckaert
-	Copyright (c) Bart Mollet, Hogeschool Gent
+    Copyright (c) 2004 Dokeos S.A.
+    Copyright (c) 2003 Ghent University (UGent)
+    Copyright (c) 2001 Universite catholique de Louvain (UCL)
+    Copyright (c) Olivier Brouckaert
+    Copyright (c) Bart Mollet, Hogeschool Gent
 
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+    For a full list of contributors, see "credits.txt".
+    The full license can be read in "license.txt".
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
 
-	See the GNU General Public License for more details.
+    See the GNU General Public License for more details.
 
-	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
+    Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
 ==============================================================================
 */
 /**
@@ -56,9 +56,9 @@ $form = new FormValidator('add_class');
 $form->add_textfield('name', get_lang('ClassName'));
 $form->addElement('style_submit_button', 'submit', get_lang('Ok'), 'class="add"');
 if ($form->validate()) {
-	$values = $form->exportValues();
-	ClassManager::create_class($values['name']);
-	header('Location: class_list.php');
+    $values = $form->exportValues();
+    ClassManager::create_class($values['name']);
+    header('Location: class_list.php');
 }
 
 // Displaying the header.

+ 16 - 16
main/admin/class_edit.php

@@ -3,24 +3,24 @@
 
 /*
 ==============================================================================
-	Dokeos - elearning and course management software
+    Dokeos - elearning and course management software
 
-	Copyright (c) 2004 Dokeos S.A.
-	Copyright (c) 2003 Ghent University (UGent)
-	Copyright (c) 2001 Universite catholique de Louvain (UCL)
-	Copyright (c) Olivier Brouckaert
+    Copyright (c) 2004 Dokeos S.A.
+    Copyright (c) 2003 Ghent University (UGent)
+    Copyright (c) 2001 Universite catholique de Louvain (UCL)
+    Copyright (c) Olivier Brouckaert
 
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+    For a full list of contributors, see "credits.txt".
+    The full license can be read in "license.txt".
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
 
-	See the GNU General Public License for more details.
+    See the GNU General Public License for more details.
 
-	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
+    Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
 ==============================================================================
 */
 /**
@@ -62,9 +62,9 @@ $form->addElement('style_submit_button', 'submit', get_lang('Ok'), 'class="add"'
 $form->setDefaults(array('name'=>$class['name']));
 if($form->validate())
 {
-	$values = $form->exportValues();
-	ClassManager :: set_name($values['name'], $class_id);
-	header('Location: class_list.php');
+    $values = $form->exportValues();
+    ClassManager :: set_name($values['name'], $class_id);
+    header('Location: class_list.php');
 }
 
 Display :: display_header($tool_name);

+ 55 - 55
main/admin/class_import.php

@@ -2,25 +2,25 @@
 // $Id: class_import.php 10215 2006-11-27 13:57:17Z pcool $
 /*
 ==============================================================================
-	Dokeos - elearning and course management software
+    Dokeos - elearning and course management software
 
-	Copyright (c) 2004 Dokeos S.A.
-	Copyright (c) 2003 Ghent University (UGent)
-	Copyright (c) 2001 Universite catholique de Louvain (UCL)
-	Copyright (c) Olivier Brouckaert
-	Copyright (c) Bart Mollet, Hogeschool Gent
+    Copyright (c) 2004 Dokeos S.A.
+    Copyright (c) 2003 Ghent University (UGent)
+    Copyright (c) 2001 Universite catholique de Louvain (UCL)
+    Copyright (c) Olivier Brouckaert
+    Copyright (c) Bart Mollet, Hogeschool Gent
 
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+    For a full list of contributors, see "credits.txt".
+    The full license can be read in "license.txt".
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
 
-	See the GNU General Public License for more details.
+    See the GNU General Public License for more details.
 
-	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
+    Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
 ==============================================================================
 */
 /**
@@ -35,37 +35,37 @@
  * Validates imported data.
  */
 function validate_data($classes) {
-	$errors = array();
-	foreach ($classes as $index => $class) {
-		// 1. Check wheter ClassName is available.
-		if (!isset($class['ClassName']) || strlen(trim($class['ClassName'])) == 0) {
-			$class['line'] = $index + 2;
-			$class['error'] = get_lang('MissingClassName');
-			$errors[] = $class;
-		}
-		// 2. Check whether class doesn't exist yet.
-		else {
-			if (ClassManager::class_name_exists($class['ClassName'])) {
-				$class['line'] = $index + 2;
-				$class['error'] = get_lang('ClassNameExists').' <strong>'.$class['ClassName'].'</strong>';
-				$errors[] = $class;
-			}
-		}
-	}
-	return $errors;
+    $errors = array();
+    foreach ($classes as $index => $class) {
+        // 1. Check wheter ClassName is available.
+        if (!isset($class['ClassName']) || strlen(trim($class['ClassName'])) == 0) {
+            $class['line'] = $index + 2;
+            $class['error'] = get_lang('MissingClassName');
+            $errors[] = $class;
+        }
+        // 2. Check whether class doesn't exist yet.
+        else {
+            if (ClassManager::class_name_exists($class['ClassName'])) {
+                $class['line'] = $index + 2;
+                $class['error'] = get_lang('ClassNameExists').' <strong>'.$class['ClassName'].'</strong>';
+                $errors[] = $class;
+            }
+        }
+    }
+    return $errors;
 }
 
 /**
  * Save imported class data to database
  */
 function save_data($classes) {
-	$number_of_added_classes = 0;
-	foreach ($classes as $index => $class) {
-		if (ClassManager::create_class($class['ClassName'])) {
-			$number_of_added_classes++;
-		}
-	}
-	return $number_of_added_classes;
+    $number_of_added_classes = 0;
+    foreach ($classes as $index => $class) {
+        if (ClassManager::create_class($class['ClassName'])) {
+            $number_of_added_classes++;
+        }
+    }
+    return $number_of_added_classes;
 }
 
 // Language files that should be included.
@@ -106,22 +106,22 @@ $form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
 $form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="save"');
 
 if ($form->validate()) {
-	$classes = Import::csv_to_array($_FILES['import_file']['tmp_name']);
-	$errors = validate_data($classes);
-	if (count($errors) == 0) {
-		$number_of_added_classes = save_data($classes);
-		Display::display_normal_message($number_of_added_classes.' '.get_lang('ClassesCreated'));
-	} else {
-		$error_message = get_lang('ErrorsWhenImportingFile');
-		$error_message .= '<ul>';
-		foreach ($errors as $index => $error_class) {
-			$error_message .= '<li>'.$error_class['error'].' ('.get_lang('Line').' '.$error_class['line'].')';
-			$error_message .= '</li>';
-		}
-		$error_message .= '</ul>';
-		$error_message .= get_lang('NoClassesHaveBeenCreated');
-		Display :: display_error_message($error_message);
-	}
+    $classes = Import::csv_to_array($_FILES['import_file']['tmp_name']);
+    $errors = validate_data($classes);
+    if (count($errors) == 0) {
+        $number_of_added_classes = save_data($classes);
+        Display::display_normal_message($number_of_added_classes.' '.get_lang('ClassesCreated'));
+    } else {
+        $error_message = get_lang('ErrorsWhenImportingFile');
+        $error_message .= '<ul>';
+        foreach ($errors as $index => $error_class) {
+            $error_message .= '<li>'.$error_class['error'].' ('.get_lang('Line').' '.$error_class['line'].')';
+            $error_message .= '</li>';
+        }
+        $error_message .= '</ul>';
+        $error_message .= get_lang('NoClassesHaveBeenCreated');
+        Display :: display_error_message($error_message);
+    }
 }
 
 $form->display();

+ 62 - 62
main/admin/class_information.php

@@ -1,24 +1,24 @@
 <?php // $Id: class_information.php 16954 2008-11-26 14:41:35Z pcool $
 /*
 ==============================================================================
-	Dokeos - elearning and course management software
+    Dokeos - elearning and course management software
 
-	Copyright (c) 2004 Dokeos S.A.
-	Copyright (c) 2003 Ghent University (UGent)
-	Copyright (c) 2001 Universite catholique de Louvain (UCL)
-	Copyright (c) Olivier Brouckaert
+    Copyright (c) 2004 Dokeos S.A.
+    Copyright (c) 2003 Ghent University (UGent)
+    Copyright (c) 2001 Universite catholique de Louvain (UCL)
+    Copyright (c) Olivier Brouckaert
 
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+    For a full list of contributors, see "credits.txt".
+    The full license can be read in "license.txt".
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
 
-	See the GNU General Public License for more details.
+    See the GNU General Public License for more details.
 
-	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
+    Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
 ==============================================================================
 */
 /**
@@ -41,7 +41,7 @@ api_protect_admin_script();
 require api_get_path(LIBRARY_PATH).'classmanager.lib.php';
 
 if (!isset($_GET['id'])) {
-	api_not_allowed();
+    api_not_allowed();
 }
 
 $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
@@ -61,37 +61,37 @@ echo '<h4>'.get_lang('Users').'</h4>';
 echo '<blockquote>';
 $users = ClassManager::get_users($class_id);
 if (count($users) > 0) {
-	$is_western_name_order = api_is_western_name_order();
-	$table_header[] = array (get_lang('OfficialCode'), true);
-	if ($is_western_name_order) {
-		$table_header[] = array (get_lang('FirstName'), true);
-		$table_header[] = array (get_lang('LastName'), true);
-	} else {
-		$table_header[] = array (get_lang('LastName'), true);
-		$table_header[] = array (get_lang('FirstName'), true);
-	}
-	$table_header[] = array (get_lang('Email'), true);
-	$table_header[] = array (get_lang('Status'), true);
-	$table_header[] = array ('', false);
-	$data = array();
-	foreach($users as $index => $user) {
-		$row = array ();
-		$row[] = $user['official_code'];
-		if ($is_western_name_order) {
-			$row[] = $user['firstname'];
-			$row[] = $user['lastname'];
-		} else {
-			$row[] = $user['lastname'];
-			$row[] = $user['firstname'];
-		}
-		$row[] = Display :: encrypted_mailto_link($user['email'], $user['email']);
-		$row[] = $user['status'] == 5 ? get_lang('Student') : get_lang('Teacher');
-		$row[] = '<a href="user_information.php?user_id='.$user['user_id'].'">'.Display::return_icon('synthese_view.gif').'</a>';
-		$data[] = $row;
-	}
-	Display::display_sortable_table($table_header,$data,array(),array(),array('id'=>$_GET['id']));
+    $is_western_name_order = api_is_western_name_order();
+    $table_header[] = array (get_lang('OfficialCode'), true);
+    if ($is_western_name_order) {
+        $table_header[] = array (get_lang('FirstName'), true);
+        $table_header[] = array (get_lang('LastName'), true);
+    } else {
+        $table_header[] = array (get_lang('LastName'), true);
+        $table_header[] = array (get_lang('FirstName'), true);
+    }
+    $table_header[] = array (get_lang('Email'), true);
+    $table_header[] = array (get_lang('Status'), true);
+    $table_header[] = array ('', false);
+    $data = array();
+    foreach($users as $index => $user) {
+        $row = array ();
+        $row[] = $user['official_code'];
+        if ($is_western_name_order) {
+            $row[] = $user['firstname'];
+            $row[] = $user['lastname'];
+        } else {
+            $row[] = $user['lastname'];
+            $row[] = $user['firstname'];
+        }
+        $row[] = Display :: encrypted_mailto_link($user['email'], $user['email']);
+        $row[] = $user['status'] == 5 ? get_lang('Student') : get_lang('Teacher');
+        $row[] = '<a href="user_information.php?user_id='.$user['user_id'].'">'.Display::return_icon('synthese_view.gif').'</a>';
+        $data[] = $row;
+    }
+    Display::display_sortable_table($table_header,$data,array(),array(),array('id'=>$_GET['id']));
 } else {
-	echo get_lang('NoUsersInClass');
+    echo get_lang('NoUsersInClass');
 }
 echo '</blockquote>';
 
@@ -100,25 +100,25 @@ echo '</blockquote>';
  */
 $courses = ClassManager::get_courses($class_id);
 if (count($courses) > 0) {
-	$header[] = array (get_lang('Code'), true);
-	$header[] = array (get_lang('Title'), true);
-	$header[] = array ('', false);
-	$data = array ();
-	foreach( $courses as $index => $course) {
-		$row = array ();
-		$row[] = $course['visual_code'];
-		$row[] = $course['title'];
-		$row[] = '<a href="course_information.php?code='.$course['code'].'">'.Display::return_icon('info_small.gif', get_lang('Delete')).'</a>'.
-					'<a href="'.api_get_path(WEB_COURSE_PATH).$course['directory'].'">'.Display::return_icon('course_home.gif', get_lang('CourseHome')).'</a>' .
-					'<a href="course_edit.php?course_code='.$course['code'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
-		$data[] = $row;
-	}
-	echo '<p><b>'.get_lang('Courses').'</b></p>';
-	echo '<blockquote>';
-	Display :: display_sortable_table($header, $data, array (), array (), array('id'=>$_GET['id']));
-	echo '</blockquote>';
+    $header[] = array (get_lang('Code'), true);
+    $header[] = array (get_lang('Title'), true);
+    $header[] = array ('', false);
+    $data = array ();
+    foreach( $courses as $index => $course) {
+        $row = array ();
+        $row[] = $course['visual_code'];
+        $row[] = $course['title'];
+        $row[] = '<a href="course_information.php?code='.$course['code'].'">'.Display::return_icon('info_small.gif', get_lang('Delete')).'</a>'.
+                    '<a href="'.api_get_path(WEB_COURSE_PATH).$course['directory'].'">'.Display::return_icon('course_home.gif', get_lang('CourseHome')).'</a>' .
+                    '<a href="course_edit.php?course_code='.$course['code'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
+        $data[] = $row;
+    }
+    echo '<p><b>'.get_lang('Courses').'</b></p>';
+    echo '<blockquote>';
+    Display :: display_sortable_table($header, $data, array (), array (), array('id'=>$_GET['id']));
+    echo '</blockquote>';
 } else {
-	echo '<p>'.get_lang('NoCoursesForThisClass').'</p>';
+    echo '<p>'.get_lang('NoCoursesForThisClass').'</p>';
 }
 
 // Displaying the footer.

+ 68 - 68
main/admin/class_list.php

@@ -2,24 +2,24 @@
 // $Id: class_list.php 20441 2009-05-10 07:39:15Z ivantcholakov $
 /*
 ==============================================================================
-	Dokeos - elearning and course management software
+    Dokeos - elearning and course management software
 
-	Copyright (c) 2004 Dokeos S.A.
-	Copyright (c) 2003 Ghent University (UGent)
-	Copyright (c) 2001 Universite catholique de Louvain (UCL)
-	Copyright (c) Olivier Brouckaert
+    Copyright (c) 2004 Dokeos S.A.
+    Copyright (c) 2003 Ghent University (UGent)
+    Copyright (c) 2001 Universite catholique de Louvain (UCL)
+    Copyright (c) Olivier Brouckaert
 
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+    For a full list of contributors, see "credits.txt".
+    The full license can be read in "license.txt".
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
 
-	See the GNU General Public License for more details.
+    See the GNU General Public License for more details.
 
-	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
+    Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
 ==============================================================================
 */
 /**
@@ -41,14 +41,14 @@ api_protect_admin_script();
  * Gets the total number of classes.
  */
 function get_number_of_classes() {
-	$tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
-	$sql = "SELECT COUNT(*) AS number_of_classes FROM $tbl_class";
-	if (isset ($_GET['keyword'])) {
-		$sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
-	}
-	$res = Database::query($sql);
-	$obj = Database::fetch_object($res);
-	return $obj->number_of_classes;
+    $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
+    $sql = "SELECT COUNT(*) AS number_of_classes FROM $tbl_class";
+    if (isset ($_GET['keyword'])) {
+        $sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
+    }
+    $res = Database::query($sql);
+    $obj = Database::fetch_object($res);
+    return $obj->number_of_classes;
 }
 
 /**
@@ -58,38 +58,38 @@ function get_number_of_classes() {
  * @param string $direction
  */
 function get_class_data($from, $number_of_items, $column, $direction) {
-	$tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
-	$tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
-	$from 				= Database::escape_string($from);
-	$number_of_items 	= Database::escape_string($number_of_items);
-	$column 			= Database::escape_string($column);
-	$direction 			= Database::escape_string($direction);
-
-	$sql = "SELECT 	id AS col0, name AS col1, COUNT(user_id) AS col2, id AS col3
-		FROM $tbl_class
-			LEFT JOIN $tbl_class_user ON id=class_id ";
-	if (isset ($_GET['keyword'])) {
-		$sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
-	}
-	$sql .= " GROUP BY id,name ORDER BY col$column $direction LIMIT $from,$number_of_items";
-	$res = Database::query($sql);
-	$classes = array ();
-	while ($class = Database::fetch_row($res)) {
-		$classes[] = $class;
-	}
-	return $classes;
+    $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
+    $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
+    $from 				= Database::escape_string($from);
+    $number_of_items 	= Database::escape_string($number_of_items);
+    $column 			= Database::escape_string($column);
+    $direction 			= Database::escape_string($direction);
+
+    $sql = "SELECT 	id AS col0, name AS col1, COUNT(user_id) AS col2, id AS col3
+        FROM $tbl_class
+            LEFT JOIN $tbl_class_user ON id=class_id ";
+    if (isset ($_GET['keyword'])) {
+        $sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
+    }
+    $sql .= " GROUP BY id,name ORDER BY col$column $direction LIMIT $from,$number_of_items";
+    $res = Database::query($sql);
+    $classes = array ();
+    while ($class = Database::fetch_row($res)) {
+        $classes[] = $class;
+    }
+    return $classes;
 }
 
 /**
  * Filter for sortable table to display edit icons for class
  */
 function modify_filter($class_id) {
-	$class_id = Security::remove_XSS($class_id);
-	$result = '<a href="class_information.php?id='.$class_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>';
-	$result .= '<a href="class_edit.php?idclass='.$class_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
-	$result .= '<a href="class_list.php?action=delete_class&amp;class_id='.$class_id.'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
-	$result .= '<a href="subscribe_user2class.php?idclass='.$class_id.'">'.Display::return_icon('add_multiple_users.gif', get_lang('AddUsersToAClass')).'</a>';
-	return $result;
+    $class_id = Security::remove_XSS($class_id);
+    $result = '<a href="class_information.php?id='.$class_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>';
+    $result .= '<a href="class_edit.php?idclass='.$class_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
+    $result .= '<a href="class_list.php?action=delete_class&amp;class_id='.$class_id.'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
+    $result .= '<a href="subscribe_user2class.php?idclass='.$class_id.'">'.Display::return_icon('add_multiple_users.gif', get_lang('AddUsersToAClass')).'</a>';
+    return $result;
 }
 
 require api_get_path(LIBRARY_PATH).'fileManage.lib.php';
@@ -103,30 +103,30 @@ Display :: display_header($tool_name);
 //api_display_tool_title($tool_name);
 
 if (isset($_POST['action'])) {
-	switch ($_POST['action']) {
-		// Delete selected classes
-		case 'delete_classes' :
-			$classes = $_POST['class'];
-			if (count($classes) > 0) {
-				foreach ($classes as $index => $class_id) {
-					ClassManager :: delete_class($class_id);
-				}
-				Display :: display_normal_message(get_lang('ClassesDeleted'));
-			}
-			break;
-	}
+    switch ($_POST['action']) {
+        // Delete selected classes
+        case 'delete_classes' :
+            $classes = $_POST['class'];
+            if (count($classes) > 0) {
+                foreach ($classes as $index => $class_id) {
+                    ClassManager :: delete_class($class_id);
+                }
+                Display :: display_normal_message(get_lang('ClassesDeleted'));
+            }
+            break;
+    }
 }
 
 if (isset($_GET['action'])) {
-	switch ($_GET['action']) {
-		case 'delete_class':
-			ClassManager :: delete_class($_GET['class_id']);
-			Display :: display_normal_message(get_lang('ClassDeleted'));
-			break;
-		case 'show_message':
-			Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
-			break;
-	}
+    switch ($_GET['action']) {
+        case 'delete_class':
+            ClassManager :: delete_class($_GET['class_id']);
+            Display :: display_normal_message(get_lang('ClassDeleted'));
+            break;
+        case 'show_message':
+            Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
+            break;
+    }
 }
 
 // Create a search-box

+ 116 - 116
main/admin/class_user_import.php

@@ -3,21 +3,21 @@
 // $Id: class_user_import.php 9018 2006-06-28 15:11:16Z evie_em $
 /*
 ==============================================================================
-	Dokeos - elearning and course management software
+    Dokeos - elearning and course management software
 
-	Copyright (c) 2005 Bart Mollet <bart.mollet@hogent.be>
+    Copyright (c) 2005 Bart Mollet <bart.mollet@hogent.be>
 
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+    For a full list of contributors, see "credits.txt".
+    The full license can be read in "license.txt".
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
 
-	See the GNU General Public License for more details.
+    See the GNU General Public License for more details.
 
-	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
+    Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
 ==============================================================================
 */
 /**
@@ -32,51 +32,51 @@
  * Validates imported data.
  */
 function validate_data($user_classes) {
-	global $purification_option_for_usernames;
-	$errors = array ();
-	$classcodes = array ();
-	foreach ($user_classes as $index => $user_class) {
-		$user_class['line'] = $index + 1;
-		// 1. Check whether mandatory fields are set.
-		$mandatory_fields = array ('UserName', 'ClassName');
-		foreach ($mandatory_fields as $key => $field) {
-			if (!isset ($user_class[$field]) || strlen($user_class[$field]) == 0) {
-				$user_class['error'] = get_lang($field.'Mandatory');
-				$errors[] = $user_class;
-			}
-		}
-		// 2. Check whether classcode exists.
-		if (isset ($user_class['ClassName']) && strlen($user_class['ClassName']) != 0) {
-			// 2.1 Check whether code has been allready used in this CVS-file.
-			if (!isset ($classcodes[$user_class['ClassName']])) {
-				// 2.1.1 Check whether code exists in DB.
-				$class_table = Database :: get_main_table(TABLE_MAIN_CLASS);
-				$sql = "SELECT * FROM $class_table WHERE name = '".Database::escape_string($user_class['ClassName'])."'";
-				$res = Database::query($sql);
-				if (Database::num_rows($res) == 0) {
-					$user_class['error'] = get_lang('CodeDoesNotExists');
-					$errors[] = $user_class;
-				} else {
-					$classcodes[$user_class['CourseCode']] = 1;
-				}
-			}
-		}
-		// 3. Check username, first, check whether it is empty.
-		if (!UserManager::is_username_empty($user_class['UserName'])) {
-			// 3.1. Check whether username is too long.
-			if (UserManager::is_username_too_long($user_class['UserName'])) {
-				$user_class['error'] = get_lang('UserNameTooLong').': '.$user_class['UserName'];
-				$errors[] = $user_class;
-			}
-			$username = UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames);
-			// 3.2. Check whether username exists.
-			if (UserManager::is_username_available($username)) {
-				$user_class['error'] = get_lang('UnknownUser').': '.$username;
-				$errors[] = $user_class;
-			}
-		}
-	}
-	return $errors;
+    global $purification_option_for_usernames;
+    $errors = array ();
+    $classcodes = array ();
+    foreach ($user_classes as $index => $user_class) {
+        $user_class['line'] = $index + 1;
+        // 1. Check whether mandatory fields are set.
+        $mandatory_fields = array ('UserName', 'ClassName');
+        foreach ($mandatory_fields as $key => $field) {
+            if (!isset ($user_class[$field]) || strlen($user_class[$field]) == 0) {
+                $user_class['error'] = get_lang($field.'Mandatory');
+                $errors[] = $user_class;
+            }
+        }
+        // 2. Check whether classcode exists.
+        if (isset ($user_class['ClassName']) && strlen($user_class['ClassName']) != 0) {
+            // 2.1 Check whether code has been allready used in this CVS-file.
+            if (!isset ($classcodes[$user_class['ClassName']])) {
+                // 2.1.1 Check whether code exists in DB.
+                $class_table = Database :: get_main_table(TABLE_MAIN_CLASS);
+                $sql = "SELECT * FROM $class_table WHERE name = '".Database::escape_string($user_class['ClassName'])."'";
+                $res = Database::query($sql);
+                if (Database::num_rows($res) == 0) {
+                    $user_class['error'] = get_lang('CodeDoesNotExists');
+                    $errors[] = $user_class;
+                } else {
+                    $classcodes[$user_class['CourseCode']] = 1;
+                }
+            }
+        }
+        // 3. Check username, first, check whether it is empty.
+        if (!UserManager::is_username_empty($user_class['UserName'])) {
+            // 3.1. Check whether username is too long.
+            if (UserManager::is_username_too_long($user_class['UserName'])) {
+                $user_class['error'] = get_lang('UserNameTooLong').': '.$user_class['UserName'];
+                $errors[] = $user_class;
+            }
+            $username = UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames);
+            // 3.2. Check whether username exists.
+            if (UserManager::is_username_available($username)) {
+                $user_class['error'] = get_lang('UnknownUser').': '.$username;
+                $errors[] = $user_class;
+            }
+        }
+    }
+    return $errors;
 }
 
 /**
@@ -84,50 +84,50 @@ function validate_data($user_classes) {
  */
 function save_data($users_classes) {
 
-	global $purification_option_for_usernames;
-
-	// Table definitions.
-	$user_table 		= Database :: get_main_table(TABLE_MAIN_USER);
-	$class_user_table 	= Database :: get_main_table(TABLE_MAIN_CLASS_USER);
-	$class_table 		= Database :: get_main_table(TABLE_MAIN_CLASS);
-
-	// Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id)
-	$csv_data = array ();
-	foreach ($users_classes as $index => $user_class) {
-		$sql1 = "SELECT user_id FROM $user_table WHERE username = '".Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames))."'";
-		$res1 = Database::query($sql1);
-		$obj1 = Database::fetch_object($res1);
-		$sql2 = "SELECT id FROM $class_table WHERE name = '".Database::escape_string(trim($user_class['ClassName']))."'";
-		$res2 = Database::query($sql2);
-		$obj2 = Database::fetch_object($res2);
-		if ($obj1 && $obj2) {
-			$csv_data[$obj1->user_id][$obj2->id] = 1;
-		}
-	}
-
-	// Logic for processing the request (data + UI options).
-	$db_subscriptions = array();
-	foreach ($csv_data as $user_id => $csv_subscriptions) {
-		$sql = "SELECT class_id FROM $class_user_table cu WHERE cu.user_id = $user_id";
-		$res = Database::query($sql);
-		while ($obj = Database::fetch_object($res)) {
-			$db_subscriptions[$obj->class_id] = 1;
-		}
-		$to_subscribe = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
-		$to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
-		// Subscriptions for new classes.
-		if ($_POST['subscribe']) {
-			foreach ($to_subscribe as $class_id) {
-				ClassManager::add_user($user_id, $class_id);
-			}
-		}
-		// Unsubscription from previous classes.
-		if ($_POST['unsubscribe']) {
-			foreach ($to_unsubscribe as $class_id) {
-				ClassManager::unsubscribe_user($user_id, $class_id);
-			}
-		}
-	}
+    global $purification_option_for_usernames;
+
+    // Table definitions.
+    $user_table 		= Database :: get_main_table(TABLE_MAIN_USER);
+    $class_user_table 	= Database :: get_main_table(TABLE_MAIN_CLASS_USER);
+    $class_table 		= Database :: get_main_table(TABLE_MAIN_CLASS);
+
+    // Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id)
+    $csv_data = array ();
+    foreach ($users_classes as $index => $user_class) {
+        $sql1 = "SELECT user_id FROM $user_table WHERE username = '".Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames))."'";
+        $res1 = Database::query($sql1);
+        $obj1 = Database::fetch_object($res1);
+        $sql2 = "SELECT id FROM $class_table WHERE name = '".Database::escape_string(trim($user_class['ClassName']))."'";
+        $res2 = Database::query($sql2);
+        $obj2 = Database::fetch_object($res2);
+        if ($obj1 && $obj2) {
+            $csv_data[$obj1->user_id][$obj2->id] = 1;
+        }
+    }
+
+    // Logic for processing the request (data + UI options).
+    $db_subscriptions = array();
+    foreach ($csv_data as $user_id => $csv_subscriptions) {
+        $sql = "SELECT class_id FROM $class_user_table cu WHERE cu.user_id = $user_id";
+        $res = Database::query($sql);
+        while ($obj = Database::fetch_object($res)) {
+            $db_subscriptions[$obj->class_id] = 1;
+        }
+        $to_subscribe = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
+        $to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
+        // Subscriptions for new classes.
+        if ($_POST['subscribe']) {
+            foreach ($to_subscribe as $class_id) {
+                ClassManager::add_user($user_id, $class_id);
+            }
+        }
+        // Unsubscription from previous classes.
+        if ($_POST['unsubscribe']) {
+            foreach ($to_unsubscribe as $class_id) {
+                ClassManager::unsubscribe_user($user_id, $class_id);
+            }
+        }
+    }
 }
 
 /**
@@ -136,8 +136,8 @@ function save_data($users_classes) {
  * @return array All course-information read from the file
  */
 function parse_csv_data($file) {
-	$courses = Import::csv_to_array($file);
-	return $courses;
+    $courses = Import::csv_to_array($file);
+    return $courses;
 }
 
 $language_file = array('admin', 'registration');
@@ -170,26 +170,26 @@ $form->addElement('checkbox', 'subscribe', get_lang('Action'), get_lang('Subscri
 $form->addElement('checkbox', 'unsubscribe', '', get_lang('UnsubscribeUserIfSubscriptionIsNotInFile'));
 $form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="save"');
 if ($form->validate()) {
-	$users_classes = parse_csv_data($_FILES['import_file']['tmp_name']);
-	$errors = validate_data($users_classes);
-	if (count($errors) == 0) {
-		save_data($users_classes);
-		header('Location: class_list.php?action=show_message&message='.urlencode(get_lang('FileImported')));
-		exit();
-	}
+    $users_classes = parse_csv_data($_FILES['import_file']['tmp_name']);
+    $errors = validate_data($users_classes);
+    if (count($errors) == 0) {
+        save_data($users_classes);
+        header('Location: class_list.php?action=show_message&message='.urlencode(get_lang('FileImported')));
+        exit();
+    }
 }
 
 Display :: display_header($tool_name);
 api_display_tool_title($tool_name);
 
 if (count($errors) != 0) {
-	$error_message = "\n";
-	foreach ($errors as $index => $error_class_user) {
-		$error_message .= get_lang('Line').' '.$error_class_user['line'].': '.$error_class_user['error'].'</b>: ';
-		$error_message .= "\n";
-	}
-	$error_message .= "\n";
-	Display :: display_error_message($error_message);
+    $error_message = "\n";
+    foreach ($errors as $index => $error_class_user) {
+        $error_message .= get_lang('Line').' '.$error_class_user['line'].': '.$error_class_user['error'].'</b>: ';
+        $error_message .= "\n";
+    }
+    $error_message .= "\n";
+    Display :: display_error_message($error_message);
 }
 
 $form->display();
@@ -206,7 +206,7 @@ adam;class01
 
 /*
 ==============================================================================
-		FOOTER
+        FOOTER
 ==============================================================================
 */
 Display :: display_footer();

+ 1 - 1
main/admin/index.php

@@ -194,7 +194,7 @@ if (api_get_setting('use_session_mode') == 'true') { ?>
         <li><a href="user_move_stats.php"><?php echo get_lang('MoveUserStats'); ?></a></li>
     <?php }
         echo Display::tag('li',Display::url(get_lang('CareersAndPromotions'), 'career_dashboard.php'));
-        //echo Display::tag('li',Display::url(get_lang('Promotions'), 'promotions.php'));
+        echo Display::tag('li',Display::url(get_lang('Groups'), 'usergroups.php'));
      ?>
     </ul>
 </div>

+ 1 - 2
main/admin/promotions.php

@@ -24,7 +24,6 @@ $htmlHeadXtra[] = api_get_jqgrid_js();
 // The header.
 Display::display_header($tool_name);
 
-
 // Tool name
 if (isset($_GET['action']) && $_GET['action'] == 'add') {
     $tool = 'Add';
@@ -49,7 +48,7 @@ $extra_params['autowidth'] = 'true'; //use the width of the parent
 $extra_params['height'] = 'auto'; //use the width of the parent
 //With this function we can add actions to the jgrid
 $action_links = 'function action_formatter (cellvalue, options, rowObject) {
-                    return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'"><img title="'.get_lang('AddSession').'" src="../img/addd.gif"></a> <a href="?action=edit&id=\'+options.rowId+\'"><img src="../img/edit.gif" title="'.get_lang('Edit').'"></a>  <a <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.gif"></a>\'; 
+                    return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'"><img title="'.get_lang('AddSession').'" src="../img/addd.gif"></a> <a href="?action=edit&id=\'+options.rowId+\'"><img src="../img/edit.gif" title="'.get_lang('Edit').'"></a> <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.gif"></a>\'; 
                  }';
 
 ?>

+ 52 - 52
main/admin/subscribe_class2course.php

@@ -3,24 +3,24 @@
 // $Id: subscribe_class2course.php 20441 2009-05-10 07:39:15Z ivantcholakov $
 /*
 ==============================================================================
-	Dokeos - elearning and course management software
+    Dokeos - elearning and course management software
 
-	Copyright (c) 2004 Dokeos S.A.
-	Copyright (c) 2003 Ghent University (UGent)
-	Copyright (c) 2001 Universite catholique de Louvain (UCL)
-	Copyright (c) Olivier Brouckaert
+    Copyright (c) 2004 Dokeos S.A.
+    Copyright (c) 2003 Ghent University (UGent)
+    Copyright (c) 2001 Universite catholique de Louvain (UCL)
+    Copyright (c) Olivier Brouckaert
 
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+    For a full list of contributors, see "credits.txt".
+    The full license can be read in "license.txt".
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
 
-	See the GNU General Public License for more details.
+    See the GNU General Public License for more details.
 
-	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
+    Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
 ==============================================================================
 */
 /**
@@ -61,41 +61,41 @@ Display :: display_header($tool_name);
 
 if ($_POST['formSent'])
 {
-	$form_sent = $_POST['formSent'];
-	$classes = is_array($_POST['ClassList']) ? $_POST['ClassList'] : array();
-	$courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array();
-	$first_letter_class = $_POST['firstLetterClass'];
-	$first_letter_course = $_POST['firstLetterCourse'];
-
-	if ($form_sent == 1)
-	{
-		if (count($classes) == 0 || count($courses) == 0)
-		{
-			Display::display_error_message(get_lang('AtLeastOneClassAndOneCourse'));
-		}
-		elseif (api_substr($_POST['formSubmit'], -2) == '>>') // add classes to courses
-		{
-			foreach ($courses as $course_code)
-			{
-				foreach ($classes as $class_id)
-				{
-					ClassManager :: subscribe_to_course($class_id, $course_code);
-				}
-			}
-			Display::display_normal_message(get_lang('ClassesSubscribed'));
-		}
-		else // remove classes from courses
-			{
-			foreach ($courses as $course_code)
-			{
-				foreach ($classes as $class_id)
-				{
-					ClassManager :: unsubscribe_from_course($class_id, $course_code);
-				}
-			}
-			Display::display_normal_message(get_lang('ClassesUnsubscribed'));
-		}
-	}
+    $form_sent = $_POST['formSent'];
+    $classes = is_array($_POST['ClassList']) ? $_POST['ClassList'] : array();
+    $courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array();
+    $first_letter_class = $_POST['firstLetterClass'];
+    $first_letter_course = $_POST['firstLetterCourse'];
+
+    if ($form_sent == 1)
+    {
+        if (count($classes) == 0 || count($courses) == 0)
+        {
+            Display::display_error_message(get_lang('AtLeastOneClassAndOneCourse'));
+        }
+        elseif (api_substr($_POST['formSubmit'], -2) == '>>') // add classes to courses
+        {
+            foreach ($courses as $course_code)
+            {
+                foreach ($classes as $class_id)
+                {
+                    ClassManager :: subscribe_to_course($class_id, $course_code);
+                }
+            }
+            Display::display_normal_message(get_lang('ClassesSubscribed'));
+        }
+        else // remove classes from courses
+            {
+            foreach ($courses as $course_code)
+            {
+                foreach ($classes as $class_id)
+                {
+                    ClassManager :: unsubscribe_from_course($class_id, $course_code);
+                }
+            }
+            Display::display_normal_message(get_lang('ClassesUnsubscribed'));
+        }
+    }
 }
 
 $sql = "SELECT id,name FROM $tbl_class WHERE name LIKE '".$first_letter_class."%' ORDER BY ". (count($classes) > 0 ? "(id IN('".implode("','", $classes)."')) DESC," : "")." name";
@@ -106,7 +106,7 @@ $result = Database::query($sql);
 $db_courses = Database::store_result($result);
 if (!empty ($error_message))
 {
-	Display :: display_normal_message($error_message);
+    Display :: display_normal_message($error_message);
 }
 ?>
 <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
@@ -144,7 +144,7 @@ if (!empty ($error_message))
 foreach ($db_classes as $class)
 {
 ?>
-	<option value="<?php echo $class['id']; ?>" <?php if(in_array($class['id'],$classes)) echo 'selected="selected"'; ?>><?php echo $class['name']; ?></option>
+    <option value="<?php echo $class['id']; ?>" <?php if(in_array($class['id'],$classes)) echo 'selected="selected"'; ?>><?php echo $class['name']; ?></option>
 <?php
 }
 ?>
@@ -161,7 +161,7 @@ foreach ($db_classes as $class)
 foreach ($db_courses as $course)
 {
 ?>
-	<option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo '('.$course['visual_code'].') '.$course['title']; ?></option>
+    <option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo '('.$course['visual_code'].') '.$course['title']; ?></option>
 <?php
 }
 ?>
@@ -173,7 +173,7 @@ foreach ($db_courses as $course)
 <?php
 /*
 ==============================================================================
-		FOOTER
+        FOOTER
 ==============================================================================
 */
 Display :: display_footer();

+ 60 - 60
main/admin/subscribe_user2class.php

@@ -2,24 +2,24 @@
 // $Id: subscribe_user2class.php 12269 2007-05-03 14:17:37Z elixir_julian $
 /*
 ==============================================================================
-	Dokeos - elearning and course management software
+    Dokeos - elearning and course management software
 
-	Copyright (c) 2004 Dokeos S.A.
-	Copyright (c) 2003 Ghent University (UGent)
-	Copyright (c) 2001 Universite catholique de Louvain (UCL)
-	Copyright (c) Olivier Brouckaert
+    Copyright (c) 2004 Dokeos S.A.
+    Copyright (c) 2003 Ghent University (UGent)
+    Copyright (c) 2001 Universite catholique de Louvain (UCL)
+    Copyright (c) Olivier Brouckaert
 
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+    For a full list of contributors, see "credits.txt".
+    The full license can be read in "license.txt".
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
 
-	See the GNU General Public License for more details.
+    See the GNU General Public License for more details.
 
-	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
+    Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
 ==============================================================================
 */
 /**
@@ -57,8 +57,8 @@ $result = Database::query($sql);
 
 if (!list ($class_name) = Database::fetch_row($result))
 {
-	header('Location: class_list.php?filtreCours='.urlencode($course));
-	exit ();
+    header('Location: class_list.php?filtreCours='.urlencode($course));
+    exit ();
 }
 
 $noPHP_SELF = true;
@@ -70,46 +70,46 @@ $interbreadcrumb[] = array ("url" => "class_list.php?filtreCours=".urlencode($co
 
 if ($_POST['formSent'])
 {
-	$form_sent = $_POST['formSent'];
-	$first_letter_left = $_POST['firstLetterLeft'];
-	$first_letter_right = $_POST['firstLetterRight'];
-	$left_user_list = is_array($_POST['LeftUserList']) ? $_POST['LeftUserList'] : array();
-	$right_user_list = is_array($_POST['RightUserList']) ? $_POST['RightUserList'] : array();
-	$add_to_class = empty ($_POST['addToClass']) ? 0 : 1;
-	$remove_from_class = empty ($_POST['removeFromClass']) ? 0 : 1;
-	if ($form_sent == 1)
-	{
-		if ($add_to_class)
-		{
-			if (count($left_user_list) == 0)
-			{
-				$error_message = get_lang('AtLeastOneUser');
-			}
-			else
-			{
-				foreach ($left_user_list as $user_id)
-				{
-					ClassManager :: add_user($user_id, $class_id);
-				}
-				header('Location: class_list.php?filtreCours='.urlencode($course));
-				exit ();
-			}
-		}
-		elseif ($remove_from_class)
-		{
-			if (count($right_user_list) == 0)
-				$error_message = get_lang('AtLeastOneUser');
-			else
-			{
-				foreach ($right_user_list as $index => $user_id)
-				{
-					ClassManager :: unsubscribe_user($user_id, $class_id);
-				}
-				header('Location: class_list.php?filtreCours='.urlencode($course));
-				exit ();
-			}
-		}
-	}
+    $form_sent = $_POST['formSent'];
+    $first_letter_left = $_POST['firstLetterLeft'];
+    $first_letter_right = $_POST['firstLetterRight'];
+    $left_user_list = is_array($_POST['LeftUserList']) ? $_POST['LeftUserList'] : array();
+    $right_user_list = is_array($_POST['RightUserList']) ? $_POST['RightUserList'] : array();
+    $add_to_class = empty ($_POST['addToClass']) ? 0 : 1;
+    $remove_from_class = empty ($_POST['removeFromClass']) ? 0 : 1;
+    if ($form_sent == 1)
+    {
+        if ($add_to_class)
+        {
+            if (count($left_user_list) == 0)
+            {
+                $error_message = get_lang('AtLeastOneUser');
+            }
+            else
+            {
+                foreach ($left_user_list as $user_id)
+                {
+                    ClassManager :: add_user($user_id, $class_id);
+                }
+                header('Location: class_list.php?filtreCours='.urlencode($course));
+                exit ();
+            }
+        }
+        elseif ($remove_from_class)
+        {
+            if (count($right_user_list) == 0)
+                $error_message = get_lang('AtLeastOneUser');
+            else
+            {
+                foreach ($right_user_list as $index => $user_id)
+                {
+                    ClassManager :: unsubscribe_user($user_id, $class_id);
+                }
+                header('Location: class_list.php?filtreCours='.urlencode($course));
+                exit ();
+            }
+        }
+    }
 }
 Display :: display_header($tool_name);
 //api_display_tool_title($tool_name);
@@ -122,7 +122,7 @@ $result = Database::query($sql);
 $right_users = Database::store_result($result);
 if (!empty ($error_message))
 {
-	Display :: display_normal_message($error_message);
+    Display :: display_normal_message($error_message);
 }
 ?>
 <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?course=<?php echo urlencode($course); ?>&amp;idclass=<?php echo $class_id; ?>" style="margin:0px;">
@@ -167,9 +167,9 @@ foreach ($left_users as $user)
     </select>
    </td>
    <td width="20%" valign="middle" align="center">
-	<input type="submit" name="addToClass" value="<?php echo get_lang('AddToClass'); ?> &gt;&gt;"/>
-	<br/><br/>
-	<input type="submit" name="removeFromClass" value="&lt;&lt; <?php echo get_lang('RemoveFromClass'); ?>"/>
+    <input type="submit" name="addToClass" value="<?php echo get_lang('AddToClass'); ?> &gt;&gt;"/>
+    <br/><br/>
+    <input type="submit" name="removeFromClass" value="&lt;&lt; <?php echo get_lang('RemoveFromClass'); ?>"/>
    </td>
    <td width="40%" align="center">
     <select name="RightUserList[]" multiple="multiple" size="20" style="width:230px;">
@@ -189,7 +189,7 @@ foreach ($right_users as $user)
 <?php
 /*
 ==============================================================================
-		FOOTER
+        FOOTER
 ==============================================================================
 */
 Display :: display_footer();

+ 158 - 158
main/admin/subscribe_user2course.php

@@ -2,25 +2,25 @@
 // $Id: subscribe_user2course.php 19597 2009-04-07 14:38:36Z pcool $
 /*
 ==============================================================================
-	Dokeos - elearning and course management software
+    Dokeos - elearning and course management software
 
-	Copyright (c) 2004-2009 Dokeos SPRL
-	Copyright (c) 2003 Ghent University (UGent)
-	Copyright (c) 2001 Universite catholique de Louvain (UCL)
-	Copyright (c) Olivier Brouckaert
+    Copyright (c) 2004-2009 Dokeos SPRL
+    Copyright (c) 2003 Ghent University (UGent)
+    Copyright (c) 2001 Universite catholique de Louvain (UCL)
+    Copyright (c) Olivier Brouckaert
 
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+    For a full list of contributors, see "credits.txt".
+    The full license can be read in "license.txt".
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
 
-	See the GNU General Public License for more details.
+    See the GNU General Public License for more details.
 
-	Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
-	Mail: info@dokeos.com
+    Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
+    Mail: info@dokeos.com
 ==============================================================================
 */
 /**
@@ -37,7 +37,7 @@
 
 /*
 ==============================================================================
-		INIT SECTION
+        INIT SECTION
 ==============================================================================
 */
 // name of the language file that needs to be included
@@ -58,7 +58,7 @@ api_protect_admin_script();
 
 /*
 -----------------------------------------------------------
-	Global constants and variables
+    Global constants and variables
 -----------------------------------------------------------
 */
 
@@ -74,7 +74,7 @@ $tbl_user 	= Database :: get_main_table(TABLE_MAIN_USER);
 
 /*
 -----------------------------------------------------------
-	Header
+    Header
 -----------------------------------------------------------
 */
 $tool_name = get_lang('AddUsersToACourse');
@@ -86,8 +86,8 @@ $htmlHeadXtra[] = '
 
 function validate_filter() {
 
-		document.formulaire.form_sent.value=0;
-		document.formulaire.submit();
+        document.formulaire.form_sent.value=0;
+        document.formulaire.submit();
 
 }
 
@@ -107,7 +107,7 @@ $form->display();
 
 /*
 ==============================================================================
-		MAIN CODE
+        MAIN CODE
 ==============================================================================
 */
 
@@ -116,126 +116,126 @@ $form->display();
 $extra_field_list= UserManager::get_extra_fields();
 $new_field_list = array();
 if (is_array($extra_field_list)) {
-	foreach ($extra_field_list as $extra_field) {
-		//if is enabled to filter and is a "<select>" field type
-		if ($extra_field[8]==1 && $extra_field[2]==4 ) {
-			$new_field_list[] = array('name'=> $extra_field[3], 'variable'=>$extra_field[1], 'data'=> $extra_field[9]);
-		}
-	}
+    foreach ($extra_field_list as $extra_field) {
+        //if is enabled to filter and is a "<select>" field type
+        if ($extra_field[8]==1 && $extra_field[2]==4 ) {
+            $new_field_list[] = array('name'=> $extra_field[3], 'variable'=>$extra_field[1], 'data'=> $extra_field[9]);
+        }
+    }
 }
 
 
 /*
 -----------------------------------------------------------
-	React on POSTed request
+    React on POSTed request
 -----------------------------------------------------------
 */
 if ($_POST['form_sent']) {
-	$form_sent = $_POST['form_sent'];
-	$users = is_array($_POST['UserList']) ? $_POST['UserList'] : array() ;
-	$courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array() ;
-	$first_letter_user = $_POST['firstLetterUser'];
-	$first_letter_course = $_POST['firstLetterCourse'];
-
-	foreach ($users as $key => $value) {
-		$users[$key] = intval($value);
-	}
-
-	if ($form_sent == 1) {
-		if ( count($users) == 0 || count($courses) == 0) {
-			Display :: display_error_message(get_lang('AtLeastOneUserAndOneCourse'));
-		} else {
-			foreach ($courses as $course_code) {
-				foreach ($users as $user_id) {
-					CourseManager::subscribe_user($user_id,$course_code);
-				}
-			}
-			Display :: display_confirmation_message(get_lang('UsersAreSubscibedToCourse'));
-		}
-	}
+    $form_sent = $_POST['form_sent'];
+    $users = is_array($_POST['UserList']) ? $_POST['UserList'] : array() ;
+    $courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array() ;
+    $first_letter_user = $_POST['firstLetterUser'];
+    $first_letter_course = $_POST['firstLetterCourse'];
+
+    foreach ($users as $key => $value) {
+        $users[$key] = intval($value);
+    }
+
+    if ($form_sent == 1) {
+        if ( count($users) == 0 || count($courses) == 0) {
+            Display :: display_error_message(get_lang('AtLeastOneUserAndOneCourse'));
+        } else {
+            foreach ($courses as $course_code) {
+                foreach ($users as $user_id) {
+                    CourseManager::subscribe_user($user_id,$course_code);
+                }
+            }
+            Display :: display_confirmation_message(get_lang('UsersAreSubscibedToCourse'));
+        }
+    }
 }
 
 /*
 -----------------------------------------------------------
-	Display GUI
+    Display GUI
 -----------------------------------------------------------
 */
 if(empty($first_letter_user)) {
-	$sql = "SELECT count(*) as nb_users FROM $tbl_user";
-	$result = Database::query($sql);
-	$num_row = Database::fetch_array($result);
-	if($num_row['nb_users']>1000)
-	{//if there are too much users to gracefully handle with the HTML select list,
-	 // assign a default filter on users names
-		$first_letter_user = 'A';
-	}
-	unset($result);
+    $sql = "SELECT count(*) as nb_users FROM $tbl_user";
+    $result = Database::query($sql);
+    $num_row = Database::fetch_array($result);
+    if($num_row['nb_users']>1000)
+    {//if there are too much users to gracefully handle with the HTML select list,
+     // assign a default filter on users names
+        $first_letter_user = 'A';
+    }
+    unset($result);
 }
 
 //Filter by Extra Fields
 $use_extra_fields = false;
 if (is_array($extra_field_list)) {
-	if (is_array($new_field_list) && count($new_field_list)>0 ) {
-		$result_list=array();
-		foreach ($new_field_list as $new_field) {
-			$varname = 'field_'.$new_field['variable'];
-			if (Usermanager::is_extra_field_available($new_field['variable'])) {
-				if (isset($_POST[$varname]) && $_POST[$varname]!='0') {
-					$use_extra_fields = true;
-					$extra_field_result[]= Usermanager::get_extra_user_data_by_value($new_field['variable'], $_POST[$varname]);
-				}
-			}
-		}
-	}
+    if (is_array($new_field_list) && count($new_field_list)>0 ) {
+        $result_list=array();
+        foreach ($new_field_list as $new_field) {
+            $varname = 'field_'.$new_field['variable'];
+            if (Usermanager::is_extra_field_available($new_field['variable'])) {
+                if (isset($_POST[$varname]) && $_POST[$varname]!='0') {
+                    $use_extra_fields = true;
+                    $extra_field_result[]= Usermanager::get_extra_user_data_by_value($new_field['variable'], $_POST[$varname]);
+                }
+            }
+        }
+    }
 }
 
 if ($use_extra_fields) {
-	$final_result = array();
-	if (count($extra_field_result)>1) {
-		for($i=0;$i<count($extra_field_result)-1;$i++) {
-			if (is_array($extra_field_result[$i+1])) {
-				$final_result  = array_intersect($extra_field_result[$i],$extra_field_result[$i+1]);
-			}
-		}
-	} else {
-		$final_result = $extra_field_result[0];
-	}
-
-	$where_filter ='';
-	if ($_configuration['multiple_access_urls']) {
-		if (is_array($final_result) && count($final_result)>0) {
-			$where_filter = " AND u.user_id IN  ('".implode("','",$final_result)."') ";
-		} else {
-			//no results
-			$where_filter = " AND u.user_id  = -1";
-		}
-	} else {
-		if (is_array($final_result) && count($final_result)>0) {
-			$where_filter = " AND user_id IN  ('".implode("','",$final_result)."') ";
-		} else {
-			//no results
-			$where_filter = " AND user_id  = -1";
-		}
-	}
+    $final_result = array();
+    if (count($extra_field_result)>1) {
+        for($i=0;$i<count($extra_field_result)-1;$i++) {
+            if (is_array($extra_field_result[$i+1])) {
+                $final_result  = array_intersect($extra_field_result[$i],$extra_field_result[$i+1]);
+            }
+        }
+    } else {
+        $final_result = $extra_field_result[0];
+    }
+
+    $where_filter ='';
+    if ($_configuration['multiple_access_urls']) {
+        if (is_array($final_result) && count($final_result)>0) {
+            $where_filter = " AND u.user_id IN  ('".implode("','",$final_result)."') ";
+        } else {
+            //no results
+            $where_filter = " AND u.user_id  = -1";
+        }
+    } else {
+        if (is_array($final_result) && count($final_result)>0) {
+            $where_filter = " AND user_id IN  ('".implode("','",$final_result)."') ";
+        } else {
+            //no results
+            $where_filter = " AND user_id  = -1";
+        }
+    }
 }
 
 $target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
 $sql = "SELECT user_id,lastname,firstname,username
-		FROM $tbl_user
-		WHERE user_id<>2 AND ".$target_name." LIKE '".$first_letter_user."%' $where_filter
-		ORDER BY ". (count($users) > 0 ? "(user_id IN(".implode(',', $users).")) DESC," : "")." ".$target_name;
+        FROM $tbl_user
+        WHERE user_id<>2 AND ".$target_name." LIKE '".$first_letter_user."%' $where_filter
+        ORDER BY ". (count($users) > 0 ? "(user_id IN(".implode(',', $users).")) DESC," : "")." ".$target_name;
 
 global $_configuration;
 if ($_configuration['multiple_access_urls']) {
-	$tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-	$access_url_id = api_get_current_access_url_id();
-	if ($access_url_id != -1){
-		$sql = "SELECT u.user_id,lastname,firstname,username  FROM ".$tbl_user ." u
-		INNER JOIN $tbl_user_rel_access_url user_rel_url
-		ON (user_rel_url.user_id = u.user_id)
-		WHERE u.user_id<>2 AND access_url_id =  $access_url_id AND (".$target_name." LIKE '".$first_letter_user."%' ) $where_filter
-		ORDER BY ". (count($users) > 0 ? "(u.user_id IN(".implode(',', $users).")) DESC," : "")." ".$target_name;
-	}
+    $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
+    $access_url_id = api_get_current_access_url_id();
+    if ($access_url_id != -1){
+        $sql = "SELECT u.user_id,lastname,firstname,username  FROM ".$tbl_user ." u
+        INNER JOIN $tbl_user_rel_access_url user_rel_url
+        ON (user_rel_url.user_id = u.user_id)
+        WHERE u.user_id<>2 AND access_url_id =  $access_url_id AND (".$target_name." LIKE '".$first_letter_user."%' ) $where_filter
+        ORDER BY ". (count($users) > 0 ? "(u.user_id IN(".implode(',', $users).")) DESC," : "")." ".$target_name;
+    }
 }
 
 $result = Database::query($sql);
@@ -245,15 +245,15 @@ unset($result);
 $sql = "SELECT code,visual_code,title FROM $tbl_course WHERE visual_code LIKE '".$first_letter_course."%' ORDER BY ". (count($courses) > 0 ? "(code IN('".implode("','", $courses)."')) DESC," : "")." visual_code";
 
 if ($_configuration['multiple_access_urls']) {
-	$tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
-	$access_url_id = api_get_current_access_url_id();
-	if ($access_url_id != -1){
-		$sql = "SELECT code, visual_code, title
-				FROM $tbl_course as course
-		  		INNER JOIN $tbl_course_rel_access_url course_rel_url
-				ON (course_rel_url.course_code= course.code)
-		  		WHERE access_url_id =  $access_url_id  AND (visual_code LIKE '".$first_letter_course."%' ) ORDER BY ". (count($courses) > 0 ? "(code IN('".implode("','", $courses)."')) DESC," : "")." visual_code";
-	}
+    $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
+    $access_url_id = api_get_current_access_url_id();
+    if ($access_url_id != -1){
+        $sql = "SELECT code, visual_code, title
+                FROM $tbl_course as course
+                  INNER JOIN $tbl_course_rel_access_url course_rel_url
+                ON (course_rel_url.course_code= course.code)
+                  WHERE access_url_id =  $access_url_id  AND (visual_code LIKE '".$first_letter_course."%' ) ORDER BY ". (count($courses) > 0 ? "(code IN('".implode("','", $courses)."')) DESC," : "")." visual_code";
+    }
 }
 
 $result = Database::query($sql);
@@ -261,18 +261,18 @@ $db_courses = Database::store_result($result);
 unset($result);
 
 if ($_configuration['multiple_access_urls']) {
-	$tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
-	$access_url_id = api_get_current_access_url_id();
-	if ($access_url_id != -1){
-		$sqlNbCours = "	SELECT course_rel_user.course_code, course.title
-			FROM $tbl_course_user as course_rel_user
-			INNER JOIN $tbl_course as course
-			ON course.code = course_rel_user.course_code
-		  	INNER JOIN $tbl_course_rel_access_url course_rel_url
-			ON (course_rel_url.course_code= course.code)
-		  	WHERE access_url_id =  $access_url_id  AND course_rel_user.user_id='".$_user['user_id']."' AND course_rel_user.status='1'
-		  	ORDER BY course.title";
-	}
+    $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
+    $access_url_id = api_get_current_access_url_id();
+    if ($access_url_id != -1){
+        $sqlNbCours = "	SELECT course_rel_user.course_code, course.title
+            FROM $tbl_course_user as course_rel_user
+            INNER JOIN $tbl_course as course
+            ON course.code = course_rel_user.course_code
+              INNER JOIN $tbl_course_rel_access_url course_rel_url
+            ON (course_rel_url.course_code= course.code)
+              WHERE access_url_id =  $access_url_id  AND course_rel_user.user_id='".$_user['user_id']."' AND course_rel_user.status='1'
+              ORDER BY course.title";
+    }
 }
 
 
@@ -282,28 +282,28 @@ if ($_configuration['multiple_access_urls']) {
 <?php
 
 if (is_array($extra_field_list)) {
-	if (is_array($new_field_list) && count($new_field_list)>0 ) {
-		echo '<h3>'.get_lang('FilterUsers').'</h3>';
-		foreach ($new_field_list as $new_field) {
-			echo $new_field['name'];
-			$varname = 'field_'.$new_field['variable'];
-			echo '&nbsp;<select name="'.$varname.'">';
-			echo '<option value="0">--'.get_lang('Select').'--</option>';
-			foreach	($new_field['data'] as $option) {
-				$checked='';
-				if (isset($_POST[$varname])) {
-					if ($_POST[$varname]==$option[1]) {
-						$checked = 'selected="true"';
-					}
-				}
-				echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
-			}
-			echo '</select>';
-			echo '&nbsp;&nbsp;';
-		}
-		echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
-		echo '<br /><br />';
-	}
+    if (is_array($new_field_list) && count($new_field_list)>0 ) {
+        echo '<h3>'.get_lang('FilterUsers').'</h3>';
+        foreach ($new_field_list as $new_field) {
+            echo $new_field['name'];
+            $varname = 'field_'.$new_field['variable'];
+            echo '&nbsp;<select name="'.$varname.'">';
+            echo '<option value="0">--'.get_lang('Select').'--</option>';
+            foreach	($new_field['data'] as $option) {
+                $checked='';
+                if (isset($_POST[$varname])) {
+                    if ($_POST[$varname]==$option[1]) {
+                        $checked = 'selected="true"';
+                    }
+                }
+                echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
+            }
+            echo '</select>';
+            echo '&nbsp;&nbsp;';
+        }
+        echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
+        echo '<br /><br />';
+    }
 }
 
 ?>
@@ -340,9 +340,9 @@ if (is_array($extra_field_list)) {
     <td width="40%" align="center">
      <select name="UserList[]" multiple="multiple" size="20" style="width:230px;">
 <?php
-		foreach ($db_users as $user) {
+        foreach ($db_users as $user) {
 ?>
-	  <option value="<?php echo $user['user_id']; ?>" <?php if(in_array($user['user_id'],$users)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')'; ?></option>
+      <option value="<?php echo $user['user_id']; ?>" <?php if(in_array($user['user_id'],$users)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')'; ?></option>
 <?php
 }
 ?>
@@ -354,9 +354,9 @@ if (is_array($extra_field_list)) {
    <td width="40%" align="center">
     <select name="CourseList[]" multiple="multiple" size="20" style="width:230px;">
 <?php
-		foreach ($db_courses as $course) {
+        foreach ($db_courses as $course) {
 ?>
-	 <option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo '('.$course['visual_code'].') '.$course['title']; ?></option>
+     <option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo '('.$course['visual_code'].') '.$course['title']; ?></option>
 <?php
 }
 ?>
@@ -368,7 +368,7 @@ if (is_array($extra_field_list)) {
 <?php
 /*
 ==============================================================================
-		FOOTER
+        FOOTER
 ==============================================================================
 */
 Display :: display_footer();

+ 1 - 1
main/admin/user_move_stats.php

@@ -632,7 +632,7 @@ else
     $navigation .= get_lang('Next');
 
 echo $navigation;
-$user_list      = UserManager::get_user_list(array(), array(), $begin, $end);
+$user_list      = UserManager::get_user_list(array(), array(), $begin, $default);
 $session_list   = SessionManager::get_sessions_list(array(),array('name'));
 $options = '';
 $options .= '<option value="0">--'.get_lang('SelectASession').'--</option>';

+ 171 - 0
main/admin/usergroups.php

@@ -0,0 +1,171 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ *  @package chamilo.admin
+ */
+
+// Language files that need to be included.
+$language_file = array('admin');
+
+$cidReset = true;
+require_once '../inc/global.inc.php';
+require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
+require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
+
+$this_section = SECTION_PLATFORM_ADMIN;
+
+api_protect_admin_script();
+
+
+//Add the JS needed to use the jqgrid
+$htmlHeadXtra[] = api_get_jqgrid_js();
+
+// The header.
+Display::display_header($tool_name);
+
+
+// Tool name
+if (isset($_GET['action']) && $_GET['action'] == 'add') {
+    $tool = 'Add';
+    $interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('Group'));
+}
+if (isset($_GET['action']) && $_GET['action'] == 'editnote') {
+    $tool = 'Modify';
+    $interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('Group'));
+}
+
+//jqgrid will use this URL to do the selects
+
+$url            = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups';
+
+//The order is important you need to check the the $column variable in the model.ajax.php file 
+$columns        = array(get_lang('Name'),get_lang('Description'),get_lang('Actions'));
+
+//Column config
+$column_model   = array(array('name'=>'name',           'index'=>'name',        'width'=>'80',   'align'=>'left'),
+                        array('name'=>'description',    'index'=>'description', 'width'=>'500',  'align'=>'left'),
+                        array('name'=>'actions',        'index'=>'actions',     'formatter'=>'action_formatter','width'=>'100',  'align'=>'left'),
+                       );            
+//Autowidth             
+$extra_params['autowidth'] = 'true';
+//height auto 
+$extra_params['height'] = 'auto'; 
+
+//With this function we can add actions to the jgrid
+$action_links = 'function action_formatter (cellvalue, options, rowObject) {
+                    return \'<a href="add_sessions_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/course_add.gif" title="'.get_lang('AddSession').'"></a>'
+                    .'<a href="add_courses_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/course_add.gif" title="'.get_lang('AddCourses').'"></a>' 
+                    .'<a href="add_users_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/add_user_big.gif" title="'.get_lang('AddUsers').'"></a>' 
+                    .'<a href="?action=edit&id=\'+options.rowId+\'"><img src="../img/edit.gif" title="'.get_lang('Edit').'"></a>'                                       
+                    .'<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.gif"></a>\'; 
+                 }';
+?>
+<script>
+$(function() {    
+<?php 
+    // grid definition see the $usergroup>display() function
+    echo Display::grid_js('usergroups',  $url,$columns,$column_model,$extra_params, array(), $action_links);       
+?> 
+});
+</script>   
+<?php
+// Tool introduction
+Display::display_introduction_section(get_lang('Groups'));
+
+$usergroup = new UserGroup();
+
+// Action handling: Adding a note
+if (isset($_GET['action']) && $_GET['action'] == 'add') {
+    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
+        api_not_allowed();
+    }
+
+    $_SESSION['notebook_view'] = 'creation_date';
+    //@todo move this in the career.lib.php
+    
+    // Initiate the object
+    $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
+    // Settting the form elements
+    $form->addElement('header', '', get_lang('Add'));
+    $form->addElement('text', 'name', get_lang('name'), array('size' => '95', 'id' => 'name'));
+    //$form->applyFilter('note_title', 'html_filter');
+    $form->addElement('html_editor', 'description', get_lang('Description'), null);
+    $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
+
+    // Setting the rules
+    $form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
+
+    // The validation or display
+    if ($form->validate()) {
+        $check = Security::check_token('post');
+        if ($check) {
+            $values = $form->exportValues();       
+            $res = $usergroup->save($values);            
+            if ($res) {
+                Display::display_confirmation_message(get_lang('Added'));
+            }
+        }
+        Security::clear_token();
+        $usergroup->display();
+    } else {
+        echo '<div class="actions">';
+        echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png').' '.get_lang('Back').'</a>';
+        echo '</div>';
+        $token = Security::get_token();
+        $form->addElement('hidden', 'sec_token');
+        $form->setConstants(array('sec_token' => $token));
+        $form->display();
+    }
+}// Action handling: Editing a note
+elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
+    // Initialize the object
+    $form = new FormValidator('career', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
+    // Settting the form elements
+    $form->addElement('header', '', get_lang('Modify'));
+    $form->addElement('hidden', 'id',intval($_GET['id']));
+    $form->addElement('text', 'name', get_lang('Name'), array('size' => '100'));
+    $form->addElement('html_editor', 'description', get_lang('description'), null);
+    $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
+
+    // Setting the defaults
+    $defaults = $usergroup->get($_GET['id']);
+    $form->setDefaults($defaults);
+
+    // Setting the rules
+    $form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
+
+    // The validation or display
+    if ($form->validate()) {
+        $check = Security::check_token('post');
+        if ($check) {
+            $values = $form->exportValues();            
+            $res = $usergroup->update($values);
+            if ($res) {
+                Display::display_confirmation_message(get_lang('Updated'));
+            }
+        }
+        Security::clear_token();
+        $usergroup->display();
+    } else {
+        echo '<div class="actions">';
+        echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png').' '.get_lang('Back').'</a>';
+        echo '</div>';
+        $token = Security::get_token();
+        $form->addElement('hidden', 'sec_token');
+        $form->setConstants(array('sec_token' => $token));
+        $form->display();
+    }
+}
+// Action handling: deleting a note
+elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
+    $res = $usergroup->delete(Security::remove_XSS($_GET['id']));
+    if ($res) {
+        Display::display_confirmation_message(get_lang('Deleted'));
+    }
+    $usergroup->display();
+} else {
+    $usergroup->display();   
+}
+
+Display :: display_footer();

+ 33 - 25
main/inc/ajax/model.ajax.php

@@ -1,44 +1,47 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-//@todo this could be integrated in the inc/lib/model.lib.php
+//@todo this could be integrated in the inc/lib/model.lib.php + try to clean this file, is not very well tested yet!
 $action = $_GET['a'];
 
 require_once '../global.inc.php';
 $libpath = api_get_path(LIBRARY_PATH);
-$table = '';
 
-// 1. Setting variables
-
-//Variables needed by jqgrid
+// 1. Setting variables needed by jqgrid
 
 $page  = intval($_REQUEST['page']); //page
-$limit = intval($_REQUEST['rows']); // quantity of rows
-$sidx  = $_REQUEST['sidx']; //index to filter         
+$limit = intval($_REQUEST['rows']); //quantity of rows
+$sidx  = $_REQUEST['sidx'];         //index to filter         
 $sord  = $_REQUEST['sord'];         //asc or desc
 if (!in_array($sord, array('asc','desc'))) {
-    $sord = 'desc';
+    $sord = 'desc'; 
 }
 // get index row - i.e. user click to sort $sord = $_GET['sord']; 
 // get the direction 
 if(!$sidx) $sidx = 1;
  
- 
-//2. Selecting the count
+//2. Selecting the count FIRST
 switch ($action) {
     case 'get_careers':        
         require_once $libpath.'career.lib.php';
         $obj        = new Career();
         $count      = $obj->get_count();
-    break;
+        break;
     case 'get_promotions':
        require_once $libpath.'promotion.lib.php';        
         $obj        = new Promotion();        
         $count      = $obj->get_count();   
-    break;
+        break;
+    case 'get_usergroups':
+        require_once $libpath.'usergroup.lib.php';        
+        $obj        = new UserGroup();        
+        $count      = $obj->get_count();   
+        break;
     default:
         exit;   
 }
+
+//3. Calculating first, end, etc
         
 $total_pages = 0;
 if ($count >0) { 
@@ -46,42 +49,47 @@ if ($count >0) {
         $total_pages = ceil($count/$limit);
     }
 }
-
 if ($page > $total_pages) { 
     $page = $total_pages;
 }     
 $start = $limit * $page - $limit; 
 
-//2. Querying the DB
+//4. Deleting an element if the user wants to
+if ($_REQUEST['oper'] == 'del') {
+    $obj->delete($_REQUEST['id']);
+}
+
+//4. Querying the DB for the elements
 $columns = array();
 switch ($action) {
-    case 'get_careers':
-        if ($_REQUEST['oper'] == 'del') {
-            $obj->delete($_REQUEST['id']);
-        }
+    case 'get_careers':  
         $columns = array('name', 'description', 'actions');                
         if(!in_array($sidx, $columns)) {
         	$sidx = 'name';
         }
         $result     = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
     break;
-    case 'get_promotions':
-        if ($_REQUEST['oper'] == 'del') {
-        	$obj->delete($_REQUEST['id']);
-        }
+    case 'get_promotions':        
         $columns = array('name', 'career', 'description', 'actions');
         if(!in_array($sidx, $columns)) {
             $sidx = 'name';
         }                  
         $result     = Database::select('p.id,p.name, p.description, c.name as career', "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c  ON c.id = p.career_id ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));       
     break;
-    default:
+    case 'get_usergroups':        
+        $columns = array('name', 'description', 'actions');                
+        if(!in_array($sidx, $columns)) {
+            $sidx = 'name';
+        }
+        $result     = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
+        break;      
+    default:    
         exit;            
 }
 //echo '<pre>';
 
-if (in_array($action, array('get_careers','get_promotions'))) {
-    //3. Creating an obj to return a json
+//5. Creating an obj to return a json
+if (in_array($action, array('get_careers','get_promotions','get_usergroups'))) { 
     $responce = new stdClass();           
     $responce->page     = $page; 
     $responce->total    = $total_pages; 

+ 43 - 33
main/inc/lib/course.lib.php

@@ -158,7 +158,7 @@ class CourseManager {
 
         $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." ";
         if (!empty($startwith)) {
-            $sql .= "WHERE LIKE title '".Database::escape_string($startwith)."%' ";
+            $sql .= "WHERE title LIKE '".Database::escape_string($startwith)."%' ";
             if ($visibility !== -1 && $visibility == strval(intval($visibility))) {
                 $sql .= " AND visibility = $visibility ";
             }
@@ -191,7 +191,7 @@ class CourseManager {
         } else {
             $sql .= ' OFFSET 0';
         }
-
+        
         return Database::store_result(Database::query($sql));
     }
 
@@ -228,10 +228,13 @@ class CourseManager {
 
     /**
      * Unsubscribe one or more users from a course
-     * @param int|array $user_id
-     * @param string $course_code
+     * 
+     * @param   mixed   user_id or an array with user ids 
+     * @param   int     session id
+     * @param   string  course code
+     * 
      */
-    public static function unsubscribe_user($user_id, $course_code) {
+    public static function unsubscribe_user($user_id, $course_code, $session_id = 0) {
 
         if (!is_array($user_id)) {
             $user_id = array($user_id);
@@ -240,6 +243,12 @@ class CourseManager {
             return;
         }
         $table_user = Database :: get_main_table(TABLE_MAIN_USER);
+                
+        if (!empty($session_id)) {
+            $session_id = intval($session_id);
+        } else {        
+        	$session_id = intval($_SESSION['id_session']);
+        }
 
         //Cleaning the $user_id variable
         if (is_array($user_id)) {
@@ -294,38 +303,34 @@ class CourseManager {
 
 
         // Unsubscribe user from the course.
-        if (!empty($_SESSION['id_session'])) { // We suppose the session is safe!
+        if (!empty($session_id)) {
             // Delete in table session_rel_course_rel_user
-            $my_session_id = intval ($_SESSION['id_session']);
             Database::query("DELETE FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
-                    WHERE id_session ='".$my_session_id."'
-                        AND course_code = '".Database::escape_string($_SESSION['_course']['id'])."'
-                        AND id_user IN ($user_ids)");
+                    WHERE id_session ='".$session_id."' AND course_code = '".Database::escape_string($_SESSION['_course']['id'])."' AND id_user IN ($user_ids)");
 
             foreach ($user_id as $uid) {
                 // check if a user is register in the session with other course
-                $sql = "SELECT id_user FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session='$my_session_id' AND id_user='$uid'";
+                $sql = "SELECT id_user FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session='$session_id' AND id_user='$uid'";
                 $rs = Database::query($sql);
                 if (Database::num_rows($rs) == 0) {
                     // Delete in table session_rel_user
                     Database::query("DELETE FROM ".Database::get_main_table(TABLE_MAIN_SESSION_USER)."
-                                     WHERE id_session ='".$my_session_id."'
-                                     AND id_user='$uid' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."");
+                                     WHERE id_session ='".$session_id."' AND id_user='$uid' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."");
                 }
 
             }
 
             // Update the table session
             $row = Database::fetch_array(Database::query("SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_USER)."
-                    WHERE id_session = '".$my_session_id."' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."  "));
+                    WHERE id_session = '".$session_id."' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."  "));
             $count = $row[0]; // number of users by session
             $result = Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_SESSION)." SET nbr_users = '$count'
-                    WHERE id = '".$my_session_id."'");
+                    WHERE id = '".$session_id."'");
 
             // Update the table session_rel_course
-            $row = Database::fetch_array(@Database::query("SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session = '$my_session_id' AND course_code = '$course_code' AND status<>2" ));
+            $row = Database::fetch_array(@Database::query("SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session = '$session_id' AND course_code = '$course_code' AND status<>2" ));
             $count = $row[0]; // number of users by session and course
-            $result = @Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)." SET nbr_users = '$count' WHERE id_session = '$my_session_id' AND course_code = '$course_code' ");
+            $result = @Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)." SET nbr_users = '$count' WHERE id_session = '$session_id' AND course_code = '$course_code' ");
 
         } else {
 
@@ -348,7 +353,7 @@ class CourseManager {
      * @return  bool    True on success, false on failure
      * @see add_user_to_course
      */
-    public static function subscribe_user($user_id, $course_code, $status = STUDENT) {
+    public static function subscribe_user($user_id, $course_code, $status = STUDENT, $session_id = 0) {
 
         if ($user_id != strval(intval($user_id))) {
             return false; //detected possible SQL injection
@@ -358,6 +363,12 @@ class CourseManager {
         if (empty ($user_id) || empty ($course_code)) {
             return false;
         }
+        
+        if (!empty($session_id)) {
+            $session_id = intval($session_id);
+        } else {        
+            $session_id = intval($_SESSION['id_session']);
+        }
 
         $status = ($status == STUDENT || $status == COURSEMANAGER) ? $status : STUDENT;
         $role_id = ($status == COURSEMANAGER) ? COURSE_ADMIN : NORMAL_COURSE_MEMBER;
@@ -369,30 +380,30 @@ class CourseManager {
         }
 
         // Check whether the user has not been already subscribed to the course.
-        if (empty($_SESSION['id_session'])) {
+        if (empty($session_id)) {
             if (Database::num_rows(@Database::query("SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
                     WHERE user_id = '$user_id' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." AND course_code = '$course_code'")) > 0) {
                 return false; // The user has been already subscribed to the course.
             }
         }
 
-        if (!empty($_SESSION['id_session'])) {
+        if (!empty($session_id)) {
 
             // Check whether the user has not already been stored in the session_rel_course_user table
             if (Database::num_rows(@Database::query("SELECT * FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
                     WHERE course_code = '".$_SESSION['_course']['id']."'
-                    AND id_session ='".$_SESSION['id_session']."'
+                    AND id_session ='".$session_id."'
                     AND id_user = '".$user_id."'")) > 0) {
                 return false;
             }
 
             // check if the user is registered in the session with other course
-            $sql = "SELECT id_user FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session='".$_SESSION['id_session']."' AND id_user='$user_id'";
+            $sql = "SELECT id_user FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session='".$session_id."' AND id_user='$user_id'";
             $rs = Database::query($sql);
             if (Database::num_rows($rs) == 0) {
                 // Check whether the user has not already been stored in the session_rel_user table
                 if (Database::num_rows(@Database::query("SELECT * FROM ".Database::get_main_table(TABLE_MAIN_SESSION_USER)."
-                        WHERE id_session ='".$_SESSION['id_session']."'
+                        WHERE id_session ='".$session_id."'
                         AND id_user = '".$user_id."' AND relation_type<>".SESSION_RELATION_TYPE_RRHH." ")) > 0) {
                     return false;
                 }
@@ -400,28 +411,26 @@ class CourseManager {
 
             // Add him/her in the table session_rel_course_rel_user
             @Database::query("INSERT INTO ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
-                    SET id_session ='".$_SESSION['id_session']."',
+                    SET id_session ='".$session_id."',
                     course_code = '".$_SESSION['_course']['id']."',
                     id_user = '".$user_id."'");
 
             // Add him/her in the table session_rel_user
             @Database::query("INSERT INTO ".Database::get_main_table(TABLE_MAIN_SESSION_USER)."
-                    SET id_session ='".$_SESSION['id_session']."',
+                    SET id_session ='".$session_id."',
                     id_user = '".$user_id."'");
 
             // Update the table session
-            $row = Database::fetch_array(@Database::query("SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_USER)." WHERE id_session = '".$_SESSION['id_session']."' AND relation_type<>".SESSION_RELATION_TYPE_RRHH.""));
+            $row = Database::fetch_array(@Database::query("SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_USER)." WHERE id_session = '".$session_id."' AND relation_type<>".SESSION_RELATION_TYPE_RRHH.""));
             $count = $row[0]; // number of users by session
-            $result = @Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_SESSION)." SET nbr_users = '$count' WHERE id = '".$_SESSION['id_session']."'");
+            $result = @Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_SESSION)." SET nbr_users = '$count' WHERE id = '".$session_id."'");
 
             // Update the table session_rel_course
-            $row = Database::fetch_array(@Database::query("SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session = '".$_SESSION['id_session']."' AND course_code = '$course_code' AND status<>2" ));
+            $row = Database::fetch_array(@Database::query("SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session = '".$session_id."' AND course_code = '$course_code' AND status<>2" ));
             $count = $row[0]; // number of users by session
-            $result = @Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)." SET nbr_users = '$count' WHERE id_session = '".$_SESSION['id_session']."' AND course_code = '$course_code' ");
-
+            $result = @Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)." SET nbr_users = '$count' WHERE id_session = '".$session_id."' AND course_code = '$course_code' ");
 
         } else {
-
             $course_sort = self::userCourseSort($user_id, $course_code);
             $result = @Database::query("INSERT INTO ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
                     SET course_code = '$course_code',
@@ -434,7 +443,6 @@ class CourseManager {
             $user_id = api_get_user_id();
             event_system(LOG_SUBSCRIBE_USER_TO_COURSE, LOG_COURSE_CODE, $course_code, $time, $user_id);
         }
-
         return (bool)$result;
     }
 
@@ -3060,5 +3068,7 @@ class CourseManager {
         }
     
         return $output;
-    }    
+    }
+
+    
 } //end class CourseManager

+ 6 - 0
main/inc/lib/database.lib.php

@@ -280,6 +280,12 @@ define('TABLE_THEMATIC_ADVANCE','thematic_advance');
 define('TABLE_CAREER',      'career');
 define('TABLE_PROMOTION',   'promotion');
 
+define('TABLE_USERGROUP',               'usergroup');
+define('TABLE_USERGROUP_REL_USER',      'usergroup_rel_user');
+define('TABLE_USERGROUP_REL_COURSE',    'usergroup_rel_course');
+define('TABLE_USERGROUP_REL_SESSION',   'usergroup_rel_session');
+
+
 
 /*		DATABASE CLASS
         The class and its methods

+ 2 - 0
main/inc/lib/promotion.lib.php

@@ -21,6 +21,8 @@ class Promotion extends Model {
     function get_all_promotions_by_career_id($career_id) {        
         return Database::select('*', $this->table, array('where'=>array('career_id = ?'=>$career_id)));
     }    
+    
+
    
     /**
      * Displays the title + grid

+ 14 - 9
main/inc/lib/sessionmanager.lib.php

@@ -955,12 +955,12 @@ class SessionManager {
 
 	/**
      * Get a list of sessions of which the given conditions match with an = 'cond'
-	 * @param array $conditions a list of condition (exemple : status=>STUDENT)
-	 * @param array $order_by a list of fields on which sort
+	 * @param  array $conditions a list of condition (exemple : 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...
+	 * @todo   optional course code parameter, optional sorting parameters...
 	*/
-	public static function get_sessions_list ($conditions = array(), $order_by = array()) {
+	public static function get_sessions_list($conditions = array(), $order_by = array()) {
 
 		$session_table =Database::get_main_table(TABLE_MAIN_SESSION);
 		$session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
@@ -978,12 +978,13 @@ class SessionManager {
 			foreach ($conditions as $field=>$value) {
                 $field = Database::escape_string($field);
                 $value = Database::escape_string($value);
-				$sql_query .= $field.' = '.$value;
+				$sql_query .= $field." '".$value."'";
 			}
 		}
 		if (count($order_by)>0) {
 			$sql_query .= ' ORDER BY '.Database::escape_string(implode(',',$order_by));
 		}
+        //echo $sql_query;
 		$sql_result = Database::query($sql_query);
         if (Database::num_rows($sql_result)>0) {
     		while ($result = Database::fetch_array($sql_result)) {
@@ -1266,10 +1267,14 @@ class SessionManager {
         Database::update($t, $params, array('promotion_id = ?'=>$promotion_id));
         
         $params['promotion_id'] = $promotion_id;
-        foreach ($list as $session_id) {
-            $session_id= intval($session_id);
-            Database::update($t, $params, array('id = ?'=>$session_id));
-        }                
+        if (!empty($list)) {
+            foreach ($list as $session_id) {
+                $session_id= intval($session_id);
+                Database::update($t, $params, array('id = ?'=>$session_id));
+            }                
+        }
     }
     
+    
+    
 }

+ 210 - 0
main/inc/lib/usergroup.lib.php

@@ -0,0 +1,210 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+*	This class provides methods for the notebook management.
+*	Include/require it in your code to use its features.
+*	@package chamilo.library
+*/
+
+require_once 'model.lib.php';
+
+class UserGroup extends Model {
+
+    var $columns = array('id', 'name','description');
+    
+	public function __construct() {
+        $this->table                        =  Database::get_main_table(TABLE_USERGROUP);
+        $this->usergroup_rel_user_table     =  Database::get_main_table(TABLE_USERGROUP_REL_USER);
+        $this->usergroup_rel_course_table   =  Database::get_main_table(TABLE_USERGROUP_REL_COURSE);
+        $this->usergroup_rel_session_table  =  Database::get_main_table(TABLE_USERGROUP_REL_SESSION);
+	}
+    
+    /**
+     * Displays the title + grid
+     */
+    function display() {
+        // action links
+        echo '<div class="actions" style="margin-bottom:20px">';
+        echo '<a href="career_dashboard.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>';       
+        echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('filenew.gif',get_lang('Add')).get_lang('Add').'</a>';                     
+        echo '</div>';   
+        echo Display::grid_html('usergroups');  
+    } 
+    
+    
+    public function get_courses_by_usergroup($id) {        
+        $results = Database::select('*',$this->usergroup_rel_course_table, array('where'=>array('usergroup_id = ?'=>$id)));
+        $array = array();
+        if (!empty($results)) {    
+            foreach($results as $row) {
+                $array[]= $row['course_id'];            
+            }
+        }                       
+        return $array;
+    }
+    
+    public function get_sessions_by_usergroup($id) {
+        $results = Database::select('*',$this->usergroup_rel_session_table, array('where'=>array('usergroup_id = ?'=>$id)));
+        $array = array();
+        if (!empty($results)) {    
+            foreach($results as $row) {
+                $array[]= $row['session_id'];            
+            }
+        }                
+        return $array;
+    }      
+    
+    public function get_users_by_usergroup($id) {
+        $results = Database::select('*',$this->usergroup_rel_user_table, array('where'=>array('usergroup_id = ?'=>$id)));
+        $array = array();
+        if (!empty($results)) {    
+            foreach($results as $row) {
+                $array[]= $row['user_id'];            
+            }
+        }                       
+        return $array; 	
+    }
+    
+    
+    /**
+     * Subscribes sessions to a group  (also adding the members of the group in the session and course)
+     * @param   int     usergroup id
+     * @param   array   list of session ids
+    */
+    function subscribe_sessions_to_usergroup($usergroup_id, $list) {
+        require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
+        
+        $t = Database::get_main_table(TABLE_USERGROUP_REL_SESSION);        
+        //Deleting relationships
+  
+        $current_list = self::get_sessions_by_usergroup($usergroup_id);
+        $user_list    = self::get_users_by_usergroup($usergroup_id);
+     
+        $delete_items = $new_items = array();
+        if (!empty($list)) {                
+            foreach ($list as $session_id) {
+                if (!in_array($session_id, $current_list)) {
+                	$new_items[] = $session_id;
+                }           	
+            }
+        }            
+        if (!empty($current_list)) {  
+            foreach($current_list as $session_id) {
+        	   if (!in_array($session_id, $list)) {
+                    $delete_items[] = $session_id;
+                }  
+            }
+        }
+
+        //Deleting items
+        if (!empty($delete_items)) {
+            foreach($delete_items as $session_id) {
+                foreach($user_list as $user_id) {
+                    SessionManager::unsubscribe_user_from_session($session_id, $user_id);
+                    /*foreach ($course_list as $course_data) {
+                        foreach($user_list as $user_id) {
+                            CourseManager::subscribe_user($user_id, $course_data['code'], $session_id);
+                        }
+                    }*/
+                }
+                Database::delete($t, array('usergroup_id = ? AND session_id = ?'=>array($usergroup_id, $session_id)));
+            }
+        }
+     
+        
+        //Addding new relationships
+        if (!empty($new_items)) {
+            foreach($new_items as $id) {                
+                $params = array('session_id'=>$id, 'usergroup_id'=>$usergroup_id);
+                Database::insert($t, $params);                
+                SessionManager::suscribe_users_to_session($session_id, $user_list);
+                /*
+                $course_list = SessionManager::get_course_list_by_session_id($id);
+                foreach ($course_list as $course_data) {
+                    foreach($user_list as $user_id) {
+                        CourseManager::subscribe_user($user_id, $course_data['code'], $id);
+                    }
+                }*/
+            }
+        }
+    }
+    
+    /**
+     * Subscribes courses to a group (also adding the members of the group in the course)
+     * @param   int     usergroup id
+     * @param   array   list of course ids
+     */
+    function subscribe_courses_to_usergroup($usergroup_id, $list) {
+        require_once api_get_path(LIBRARY_PATH).'course.lib.php';
+        
+        $t = Database::get_main_table(TABLE_USERGROUP_REL_COURSE);        
+        //Deleting relationships
+  
+        $current_list = self::get_courses_by_usergroup($usergroup_id);
+        $user_list    = self::get_users_by_usergroup($usergroup_id);
+     
+        $delete_items = $new_items = array();
+        if (!empty($list)) {                
+            foreach ($list as $id) {
+                if (!in_array($id, $current_list)) {
+                    $new_items[] = $id;
+                }               
+            }
+        }
+        if (!empty($current_list)) {         
+            foreach($current_list as $id) {
+                if (!in_array($id, $list)) {
+                    $delete_items[] = $id;
+                }  
+            }
+        }
+        
+        //Deleting items
+        if (!empty($delete_items)) {
+            foreach($delete_items as $course_id) {
+                $course_info = api_get_course_info_by_id($course_id);     
+                foreach($user_list as $user_id) {                                   
+                    CourseManager::unsubscribe_user($user_id, $course_info['code']);                    
+                }
+                Database::delete($t, array('usergroup_id = ? AND course_id = ?'=>array($usergroup_id, $course_id)));
+            }
+        }
+        
+        //Addding new relationships
+        if (!empty($new_items)) {
+            foreach($new_items as $course_id) {                
+                $course_info = api_get_course_info_by_id($course_id);    
+                
+                foreach($user_list as $user_id) {         
+                    CourseManager::subscribe_user($user_id, $course_info['code']);
+                }
+                 
+                $params = array('course_id'=>$id, 'usergroup_id'=>$usergroup_id);
+                Database::insert($t, $params);
+            }
+        }
+    }   
+    
+     /**
+     * Subscribes users to a group
+     * @param   int     usergroup id
+     * @param   array   list of user ids
+     */
+    function subscribe_users_to_usergroup($usergroup_id, $list) {
+        $t = Database::get_main_table(TABLE_USERGROUP_REL_USER);            
+        $user_list = self::get_users_by_usergroup($usergroup_id);        
+            
+        //Deleting relationships
+        Database::delete($t, array('usergroup_id = ?'=>$usergroup_id));
+        
+        //Adding new relationships
+        if (!empty($list)) {
+            foreach($list as $id) {
+                $params = array('user_id'=>$id, 'usergroup_id'=>$usergroup_id);
+                Database::insert($t, $params);
+            }
+        }
+    }
+    
+}

+ 7 - 1
main/inc/lib/usermanager.lib.php

@@ -587,7 +587,7 @@ class UserManager
 	* @return array An array with all users of the platform.
 	* @todo optional course code parameter, optional sorting parameters...
 	*/
-	public static function get_user_list($conditions = array(), $order_by = array()) {
+	public static function get_user_list($conditions = array(), $order_by = array(), $limit_from = false, $limit_to = false) {
 		$user_table = Database :: get_main_table(TABLE_MAIN_USER);
 		$return_array = array();
 		$sql_query = "SELECT * FROM $user_table";
@@ -602,6 +602,12 @@ class UserManager
 		if (count($order_by) > 0) {
 			$sql_query .= ' ORDER BY '.Database::escape_string(implode(',', $order_by));
 		}
+        
+        if (is_numeric($limit_from) && is_numeric($limit_from)) {
+            $limit_from = intval($limit_from);
+            $limit_to   = intval($limit_to);
+            $sql_query .= " LIMIT $limit_from, $limit_to";  
+        }        
 		$sql_result = Database::query($sql_query);
 		while ($result = Database::fetch_array($sql_result)) {
 			$return_array[] = $result;

+ 22 - 2
main/install/db_main.sql

@@ -2547,8 +2547,6 @@ CREATE TABLE career (
     PRIMARY KEY (id)
 );
 
-
-
 CREATE TABLE promotion (
     id INT NOT NULL AUTO_INCREMENT,
     name VARCHAR(255) NOT NULL ,
@@ -2557,3 +2555,25 @@ CREATE TABLE promotion (
     PRIMARY KEY(id)
 );
 
+
+CREATE TABLE usergroup ( 
+	id INT NOT NULL AUTO_INCREMENT,	
+	name VARCHAR(255) NOT NULL, 
+	description TEXT NOT NULL,
+PRIMARY KEY (id)
+);
+
+CREATE TABLE usergroup_rel_user    ( 
+	usergroup_id INT NOT NULL, 
+	user_id 	INT NOT NULL 
+);
+
+CREATE TABLE usergroup_rel_course  ( 
+	usergroup_id INT NOT NULL, 
+	course_id 	INT NOT NULL 
+);
+
+CREATE TABLE usergroup_rel_session ( 
+	usergroup_id INT NOT NULL, 
+	session_id  INT NOT NULL 
+);

+ 7 - 1
main/install/migrate-db-1.8.7-1.8.8-pre.sql

@@ -174,6 +174,12 @@ INSERT INTO course_setting(variable,value,category) VALUES ('enable_lp_auto_laun
 INSERT INTO course_setting(variable,value,category) VALUES ('pdf_export_watermark_text','','course');
 
 
-CREATE TABLE career (	id INT NOT NULL AUTO_INCREMENT,	name VARCHAR(255) NOT NULL ,description TEXT NOT NULL,PRIMARY KEY (id));
+CREATE TABLE career (id INT NOT NULL AUTO_INCREMENT,	name VARCHAR(255) NOT NULL, description TEXT NOT NULL,PRIMARY KEY (id));
 CREATE TABLE promotion (id INT NOT NULL AUTO_INCREMENT,	name VARCHAR(255) NOT NULL, description TEXT NOT NULL, career_id INT NOT NULL,PRIMARY KEY(id));
 ALTER TABLE session ADD promotion_id INT NOT NULL;
+
+CREATE TABLE usergroup ( id INT NOT NULL AUTO_INCREMENT,	name VARCHAR(255) NOT NULL, description TEXT NOT NULL,PRIMARY KEY (id));
+
+CREATE TABLE usergroup_rel_user    ( usergroup_id INT NOT NULL, user_id 	INT NOT NULL );
+CREATE TABLE usergroup_rel_course  ( usergroup_id INT NOT NULL, course_id 	INT NOT NULL );
+CREATE TABLE usergroup_rel_session ( usergroup_id INT NOT NULL, session_id  INT NOT NULL );