Browse Source

Merge remote-tracking branch 'origin/1.10.x' into 1.11.x

Julio 9 years ago
parent
commit
bf0b4afb11

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

@@ -2609,7 +2609,7 @@ class SessionManager
      * @return array An array with all sessions of the platform.
      * @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(), $from = null, $to = null)
     {
         $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
         $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
@@ -2679,6 +2679,12 @@ class SessionManager
             }
         }
 
+        if (!is_null($from) && !is_null($to)) {
+            $to = intval($to);
+            $from = intval($from);
+            $sql_query .= "LIMIT $from, $to";
+        }
+
         $sql_result = Database::query($sql_query);
         if (Database::num_rows($sql_result) > 0) {
             while ($result = Database::fetch_array($sql_result)) {

+ 20 - 0
main/inc/lib/urlmanager.lib.php

@@ -757,6 +757,26 @@ class UrlManager
         return $result;
     }
 
+    /**
+     * Deletes user from all portals
+     * @author Julio Montoya
+     * @param int user id
+     *
+     * @return boolean true if success
+     * */
+    public static function deleteUserFromAllUrls($userId)
+    {
+        $table_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
+        $result = true;
+        if (!empty($userId)) {
+            $sql= "DELETE FROM $table_url_rel_user
+                   WHERE user_id = ".intval($userId);
+            Database::query($sql);
+        }
+
+        return $result;
+    }
+
     /**
     * Deletes an url and course relationship
     * @author Julio Montoya

+ 11 - 9
main/inc/lib/usermanager.lib.php

@@ -475,12 +475,12 @@ class UserManager
      */
     public static function can_delete_user($user_id)
     {
-        global $_configuration;
-        if (isset($_configuration['deny_delete_users']) &&
-            $_configuration['deny_delete_users'] == true
-        ) {
+        $deny = api_get_configuration_value('deny_delete_users');
+
+        if ($deny) {
             return false;
         }
+
         $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
         if ($user_id != strval(intval($user_id))) {
             return false;
@@ -493,12 +493,14 @@ class UserManager
         $res = Database::query($sql);
         while ($course = Database::fetch_object($res)) {
             $sql = "SELECT id FROM $table_course_user
-                    WHERE status=1 AND c_id = " . Database::escape_string($course->c_id);
+                    WHERE status=1 AND c_id = " . intval($course->c_id);
             $res2 = Database::query($sql);
             if (Database::num_rows($res2) == 1) {
+
                 return false;
             }
         }
+
         return true;
     }
 
@@ -612,8 +614,7 @@ class UserManager
         $extraFieldValue = new ExtraFieldValue('user');
         $extraFieldValue->deleteValuesByItem($user_id);
 
-        $url_id = api_get_current_access_url_id();
-        UrlManager::delete_url_rel_user($user_id, $url_id);
+        UrlManager::deleteUserFromAllUrls($user_id);
 
         if (api_get_setting('allow_social_tool') == 'true') {
             $userGroup = new UserGroup();
@@ -648,12 +649,13 @@ class UserManager
                 WHERE lastedit_user_id = '".$user_id."'";
         Database::query($sql);
 
+
+
+
         // Delete user from database
         $sql = "DELETE FROM $table_user WHERE id = '".$user_id."'";
         Database::query($sql);
 
-
-
         // Add event to system log
         $user_id_manager = api_get_user_id();
 

+ 9 - 3
main/webservices/registration.soap.php

@@ -5992,6 +5992,8 @@ $server->wsdl->addComplexType(
     'all',
     '',
     array(
+        'from'  => array('name' => 'from',  'type' => 'xsd:int'),
+        'to'    => array('name' => 'to',    'type' => 'xsd:int'),
         'date_start'  => array('name' => 'date_start',  'type' => 'xsd:string'),
         'date_end'    => array('name' => 'date_end',    'type' => 'xsd:string'),
         'secret_key'  => array('name' => 'secret_key',  'type' => 'xsd:string')
@@ -6048,8 +6050,9 @@ $server->register('WSListSessions',           // method name
  * @param array List of parameters (security key, date_start and date_end)
  * @return array Sessions list (id=>[title=>'title',url='http://...',date_start=>'...',date_end=>''])
  */
-function WSListSessions($params) {
-    if(!WSHelperVerifyKey($params)) {
+function WSListSessions($params)
+{
+    if (!WSHelperVerifyKey($params)) {
         return returnError(WS_ERROR_SECRET_KEY);
     }
     $sql_params = array();
@@ -6060,7 +6063,10 @@ function WSListSessions($params) {
     if (!empty($params['date_end'])) {
         $sql_params['s.access_end_date'] = array('operator' => '<=', 'value' => $params['date_end']);
     }
-    $sessions_list = SessionManager::get_sessions_list($sql_params);
+    $from = isset($params['from']) ? $params['from'] : null;
+    $to = isset($params['to']) ? $params['to'] : null;
+
+    $sessions_list = SessionManager::get_sessions_list($sql_params, null, $from, $to);
     $return_list = array();
     foreach ($sessions_list as $session) {
         $return_list[] = array(