From 2232b9ec25328bcadcc219250c4b8fb66b3d2c97 Mon Sep 17 00:00:00 2001
From: Sarika Padmashali <sarika.padmashali92@yahoo.in>
Date: Thu, 15 Dec 2016 22:49:42 -0800
Subject: [PATCH] delete multiple users

---
 src/controllers/components/SocialComponent.php | 35 +++++++++++++++++++-
 src/views/elements/ManagegroupsElement.php     | 46 ++++++++++++++++++++++++--
 2 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/src/controllers/components/SocialComponent.php b/src/controllers/components/SocialComponent.php
index 761c8d5..3878fad 100644
--- a/src/controllers/components/SocialComponent.php
+++ b/src/controllers/components/SocialComponent.php
@@ -86,7 +86,7 @@ class SocialComponent extends Component implements CrawlConstants
             "creategroup", "deletegroup", "deleteuser", "editgroup",
             "graphstats", "inviteusers", "joingroup", "memberaccess",
             "postlifetime", "registertype", "reinstateuser", "search",
-            "statistics", "unsubscribe", "voteaccess"];
+            "statistics", "unsubscribe", "voteaccess", "deleteall"];
         $data["ELEMENT"] = "managegroups";
         $data['SCRIPT'] = "";
         $data['FORM_TYPE'] = "addgroup";
@@ -189,6 +189,39 @@ class SocialComponent extends Component implements CrawlConstants
         if (isset($_REQUEST['arg']) &&
             in_array($_REQUEST['arg'], $possible_arguments)) {
             switch ($_REQUEST['arg']) {
+                case "deleteall":
+                    $_REQUEST['arg'] = "deleteAll";
+                    if (!empty($_REQUEST['context']) &&
+                        $_REQUEST['context']=='search') {
+                        $data['context'] = 'search';
+                    }
+                    $deleted = true;
+                    if(isset($_REQUEST['user_ids'])) {
+                        $users = $_REQUEST['user_ids'];
+                        $ids = explode("*", $users);
+                        foreach ($ids as $user_id) {
+                        if ($is_owner && $group_model->deletableUser(
+                        $user_id, $group_id)){
+                            $group_model->deleteUserGroup(
+                            $user_id, $group_id);
+                            $deleted = true;
+                        } else {
+                            $deleted = false;
+                        }
+                        }
+                    }
+                    if($deleted == true) {
+                        return $parent->redirectWithMessage(
+                            tl('social_component_user_deleted'),
+                            ["visible_users", 'start_row', 'context',
+                            'end_row', 'num_show', 'user_filter','group_limit']);
+                    } else {
+                       return $parent->redirectWithMessage(
+                            tl('social_component_no_delete_user_group'),
+                            ["visible_users", 'start_row', 'context',
+                            'end_row', 'num_show', 'user_filter','group_limit']);
+                    }
+                    break;
                 case "activateuser":
                     $_REQUEST['arg'] = "editgroup";
                     $user_id = (isset($_REQUEST['user_id'])) ?
diff --git a/src/views/elements/ManagegroupsElement.php b/src/views/elements/ManagegroupsElement.php
index 9841a0b..c3c2215 100755
--- a/src/views/elements/ManagegroupsElement.php
+++ b/src/views/elements/ManagegroupsElement.php
@@ -111,7 +111,8 @@ class ManagegroupsElement extends Element
                 <th><?= tl('managegroups_element_registertype')?></th>
                 <th><?= tl('managegroups_element_memberaccess')?></th>
                 <th><?= tl('managegroups_element_voting')?></th>
-                <th><?= tl('managegroups_element_post_lifetime') ?></th>
+                <th><?= tl('managegroups_element_post_lifetime')?></th>
+                <th><?= tl('managegroups_element_join_date')?></th>
                 <?php } ?>
                 <th colspan='2'><?=tl('managegroups_element_actions') ?></th>
             </tr>
@@ -136,7 +137,7 @@ class ManagegroupsElement extends Element
             $edit_url = $base_url . "&amp;arg=editgroup&amp;";
             $transfer_url = $base_url . "&amp;arg=changeowner&amp;";
             $mobile_columns = ['GROUP_NAME', 'OWNER'];
-            $ignore_columns = ["GROUP_ID", "OWNER_ID", "JOIN_DATE",
+            $ignore_columns = ["GROUP_ID", "OWNER_ID",
                 "NUM_MEMBERS"];
             if (isset($data['browse'])) {
                 $igore_columns[] = 'STATUS';
@@ -483,6 +484,10 @@ class ManagegroupsElement extends Element
                             e("<td>" . tl('managegroups_element_groupowner') .
                                 "</td><td><span class='gray'>".
                             tl('managegroups_element_delete')."</span></td>");
+                            e("<input id='markers' type = 'hidden' name='markers'>");
+                            e("<td><a id = 'deleteAll' onclick='return get_ids".
+                                "(this.id,this.href);' href='$action_url&amp;arg=deleteall&amp'>".
+                                tl('managegroups_element_deleteall')."</a></td>");
                         } else {
                             e("<td>".$data['MEMBERSHIP_CODES'][
                                 $user_array['STATUS']]);
@@ -519,6 +524,9 @@ class ManagegroupsElement extends Element
                                     e("<td></td>");
                                     break;
                             }
+                            e("<td>".date('m/d/Y', $user_array["JOIN_DATE"]));
+                            e("<td><input type='checkbox' value=".$user_array['USER_ID'].
+                                " name= ".$user_array['USER_ID']."></input><td>");
                             e("<td><a href='$action_url&amp;arg=deleteuser".
                                 "$limit'>".
                                 tl('managegroups_element_delete')."</a></td>");
@@ -594,6 +602,40 @@ class ManagegroupsElement extends Element
                 ? 'false' : 'true';
             elt('group-form').submit();
         }
+        function get_ids(element_id,element_href)
+        {
+            var collection = elt(element_id);
+            var users = elt('markers').value;
+            var arr = JSON.parse(users);
+            arr = arr.join("*");
+            collection.href = element_href+'user_ids='+arr;
+        }
+        var user_ids = [];
+        function attachCheckboxHandlers()
+        {
+            var tops = document.getElementsByTagName('input');
+            for (var i=0, len=tops.length; i<len; i++) {
+            if ( tops[i].type === 'checkbox' ) {
+                tops[i].onclick = updateTotal;
+            }
+        }
+        }
+        function updateTotal(e)
+        {
+            var form = this.form;
+            if (this.checked) {
+              user_ids.push(this.value);
+            } else {
+                var index = user_ids.indexOf(this.value);
+                if (index > -1){
+                     user_ids.splice(index, 1);
+            }
+
+        }
+        var marker_field = document.getElementById('markers');
+        marker_field.value= JSON.stringify(user_ids);
+        }
+        attachCheckboxHandlers();
         </script>
         <?php
     }
-- 
2.6.4

