From e15bce475b873fb2ccb0324c68804084bb648624 Mon Sep 17 00:00:00 2001
From: munjoob <35959208+munjoob@users.noreply.github.com>
Date: Fri, 14 Dec 2018 00:52:30 +0200
Subject: [PATCH] users can delete there files in one click
add "delete all my files" button to file user so users can delete there files in one click
and add log to cache
---
lang/ar/common.php | 5 ++-
lang/en/common.php | 3 ++
styles/bootstrap/fileuser.html | 1 +
styles/default/fileuser.html | 1 +
ucp.php | 80 +++++++++++++++++++++++++++++++++-
5 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/lang/ar/common.php b/lang/ar/common.php
index f73937c..00100e7 100755
--- a/lang/ar/common.php
+++ b/lang/ar/common.php
@@ -61,7 +61,10 @@ return array(
'LOGOUT_ERROR' => 'هناك مشكلة بالخروج',
#'FILECP' => 'إدارة الملفات',
'DEL_SELECTED' => 'حذف المحدد',
- #'EDIT_U_FILES' => 'إدارة ملفاتك',
+ 'DEL_ALL' => 'حذف كل ملفاتي',
+ 'ALL_DELETED' => 'تم حذف كل ملفاتك',
+ 'NO_FILES_DELETE' => 'لا تملك ملفات لحذفها',
+ #'EDIT_U_FILES' => 'إدارة ملفاتك',
'FILES_UPDATED' => 'تم تحديث الملفات بنجاح',
'PUBLIC_USER_FILES' => 'مجلد ملفات العضو',
'FILEUSER' => 'مجلد ملفات',
diff --git a/lang/en/common.php b/lang/en/common.php
index f161590..976074d 100755
--- a/lang/en/common.php
+++ b/lang/en/common.php
@@ -50,6 +50,9 @@ return array(
'LOGOUT_SUCCESFUL' => 'Logged out successfully.',
'LOGOUT_ERROR' => 'Logout Error!',
'DEL_SELECTED' => 'Delete selected',
+ 'DEL_ALL' => 'Delete all my files',
+ 'ALL_DELETED' => 'All files has been deleted',
+ 'NO_FILES_DELETE' => 'There is no files to delete them',
'FILES_UPDATED' => 'File updated successfully.',
'PUBLIC_USER_FILES' => 'User files' folder',
'FILEUSER' => 'files' folder',
diff --git a/styles/bootstrap/fileuser.html b/styles/bootstrap/fileuser.html
index 23e3835..4eb4e84 100755
--- a/styles/bootstrap/fileuser.html
+++ b/styles/bootstrap/fileuser.html
@@ -85,6 +85,7 @@
diff --git a/styles/default/fileuser.html b/styles/default/fileuser.html
index f2b275b..041b094 100755
--- a/styles/default/fileuser.html
+++ b/styles/default/fileuser.html
@@ -108,6 +108,7 @@
+
{H_FORM_KEYS}
diff --git a/ucp.php b/ucp.php
index fac0d9d..697b7f2 100755
--- a/ucp.php
+++ b/ucp.php
@@ -381,8 +381,10 @@ switch (g('go'))
if($nums_rows != 0)
{
$no_results = false;
-
+ if (!ip('submit_all_files')) // in delete all files we do not need any limit;
+ {
$query['LIMIT'] = "$start, $perpage";
+ }
is_array($plugin_run_result = Plugins::getInstance()->run('qr_select_files_in_fileuser', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
$result = $SQL->build($query);
@@ -457,6 +459,37 @@ switch (g('go'))
$sizes += $row['size'];
}
}
+
+ if (ip('submit_all_files') && $user_himself)
+ {
+ is_array($plugin_run_result = Plugins::getInstance()->run('submit_in_all_fileuser', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
+ //delete all files
+ foreach($arr as $row)
+ {
+
+ @kleeja_unlink($row['folder'] . '/' . $row['name'] );
+
+ //delete thumb
+ if (file_exists($row['folder'] . '/thumbs/' . $row['name'] ))
+ {
+ @kleeja_unlink($row['folder'] . '/thumbs/' . $row['name'] );
+ }
+
+ $ids[] = $row['id'];
+ if($is_image)
+ {
+ $imgs_num++;
+ }
+ else
+ {
+ $files_num++;
+ }
+
+ $sizes += $r['size'];
+
+ }
+
+ }
}
$SQL->freeresult($result_p);
@@ -498,6 +531,51 @@ switch (g('go'))
kleeja_info($lang['NO_FILE_SELECTED'], '', true, $linkgoto, 2);
}
}
+
+
+ if (ip('submit_all_files') && $user_himself)
+ {
+ if(isset($ids) && !empty($ids))
+ {
+ $query_del = array(
+ 'DELETE' => "{$dbprefix}files",
+ 'WHERE' => "id IN (" . implode(',', $ids) . ")"
+ );
+
+ is_array($plugin_run_result = Plugins::getInstance()->run('qr_del_files_in_filecp', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
+ $SQL->build($query_del);
+
+ if(($files_num <= $stat_files) && ($imgs_num <= $stat_imgs))
+ {
+ //update number of stats
+ $update_query = array(
+ 'UPDATE' => "{$dbprefix}stats",
+ 'SET' => "sizes=sizes-$sizes,files=files-$files_num, imgs=imgs-$imgs_num",
+ );
+
+ $SQL->build($update_query);
+ }
+
+
+ //write all delete log for current user for last time only
+ $log_msg=$usrcp->name()." has deleted all his/her files at this time : " . date('H:i a, d-m-Y') . "] \r\n".
+ "files numbers:".$files_num."\r\n".
+ "images numbers:".$imgs_num."\r\n";
+ $last_id=PATH . 'cache/'.$usrcp->id(); //based on user id
+ file_put_contents($last_id,$log_msg);
+
+ //delete all files , show msg
+ kleeja_info($lang['ALL_DELETED'], '', true, $linkgoto, 2);
+
+
+ }
+ else
+ {
+ //no file selected, show msg
+ kleeja_info($lang['NO_FILES_DELETE'], '', true, $linkgoto, 2);
+ }
+
+ }
}#num result
is_array($plugin_run_result = Plugins::getInstance()->run('end_fileuser', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook