Parcourir la source

Various Minor Fixes (#615)

* Added Group Exists Check

* Fixed some deprecated warnings php 8.x

* Added Group Exists Check

* Added Group Exists Check

* Minor PHP Syntax Changes
OwN-3m-All il y a 2 ans
Parent
commit
dd7e3c2048

+ 2 - 0
includes/database.php

@@ -83,6 +83,8 @@ abstract class OGPDatabase {
     abstract public function getUserList_limit($page_user,$limit_user,$search_field);
 
     abstract public function getGroupList();
+    
+    abstract public function getGroupByName($group);
 
     abstract public function getUsersGroups($user_id);
     

+ 9 - 1
includes/database_mysqli.php

@@ -306,6 +306,14 @@ class OGPDatabaseMySQL extends OGPDatabase
 		return $this->listQuery($query);
 	}
 	
+	public function getGroupByName($group) {
+		$query = sprintf("SELECT *
+			FROM %suser_group_info WHERE group_name = '%s'",
+			$this->table_prefix,
+			$this->realEscapeSingle($group));
+		return $this->listQuery($query);
+	}
+	
 	public function get_group_count($search_field){
 		$search_field = $this->realEscapeSingle($search_field);
 		
@@ -3723,7 +3731,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 				$ed = $dateTime->getTimestamp();
 			}
 			$type = $type != "group" ? $type : "user_group";
-			$query = sprintf("UPDATE `%s${type}_homes` SET `${type}_expiration_date` = '%s' WHERE `home_id` = %d",
+			$query = sprintf("UPDATE `%s" . $type . "_homes` SET `" . $type . "_expiration_date` = '%s' WHERE `home_id` = %d",
 				$this->table_prefix,
 				$ed,
 				$this->realEscapeSingle($home_id));

+ 8 - 8
includes/view.php

@@ -133,9 +133,9 @@ class OGPView {
 			{
 				$global_js_file = 'js/' . MODULES . "{$m['folder']}_global.js";
 				if(is_readable($path . $global_js_file)) // Priority to the theme's js
-					$javascript .= "<script type=\"text/javascript\" src=\"${path}${global_js_file}\"></script>\n";
+					$javascript .= "<script type=\"text/javascript\" src=\"" . $path . $global_js_file . "\"></script>\n";
 				elseif(is_readable($global_js_file))
-					$javascript .= "<script type=\"text/javascript\" src=\"${global_js_file}\"></script>\n";
+					$javascript .= "<script type=\"text/javascript\" src=\"" . $global_js_file . "\"></script>\n";
 			}
 		}
 		
@@ -144,15 +144,15 @@ class OGPView {
 		{
 			$subpage = (isset($_GET['p']) and !empty($_GET['p']))?$_GET['p']:$_GET['m'];
 			$fc = array(
-				$path . MODULES . "{$_GET['m']}/${subpage}.css",
-				$path . MODULES . "{$_GET['m']}/{$_GET['m']}.css",
-				MODULES . "{$_GET['m']}/${subpage}.css",
-				MODULES . "{$_GET['m']}/{$_GET['m']}.css"
+				$path . MODULES . $_GET['m'] . "/" . $subpage . ".css",
+				$path . MODULES . $_GET['m'] . "/" . $_GET['m'] . ".css",
+				MODULES . $_GET['m'] . "/" . $subpage . ".css",
+				MODULES . $_GET['m'] . "/" . $_GET['m'] . ".css"
 			);
 			
 			foreach($fc as $file_check){
 				if(is_readable($file_check)){
-					$stylesheet .= "<link rel=\"stylesheet\" href=\"${file_check}\">\n";
+					$stylesheet .= "<link rel=\"stylesheet\" href=\"" . $file_check . "\">\n";
 					break;
 				}
 			}
@@ -164,7 +164,7 @@ class OGPView {
 			
 			foreach($fc as $file_check){
 				if(is_readable($file_check)){
-					$javascript .= "<script type=\"text/javascript\" src=\"${file_check}\"></script>\n";
+					$javascript .= "<script type=\"text/javascript\" src=\"" . $file_check . "\"></script>\n";
 					break;
 				}
 			}

+ 1 - 0
lang/English/modules/user_admin.php

@@ -92,6 +92,7 @@ define('OGP_LANG_assign_homes', "Assign Homes");
 define('OGP_LANG_successfully_added_group', "Successfully added group %s.");
 define('OGP_LANG_group_name_empty', "Group name can not be empty.");
 define('OGP_LANG_failed_to_add_group', "Failed to add group %s.");
+define('OGP_LANG_failed_to_add_group_exists_already', "Group with the name of %s already exists. Please try a different group name.");
 define('OGP_LANG_could_not_add_user_to_group', "Could not add user %s to group %s, because already belongs.");
 define('OGP_LANG_successfully_added_to_group', ">Successfully added %s to group <em>%s</em>.");
 define('OGP_LANG_could_not_add_server_to_group', "Could not add server to group %s, because already belongs.");

+ 1 - 1
modules/addonsmanager/addons_installer.php

@@ -166,7 +166,7 @@ function exec_ogp_module() {
 		$pct = $pct > 100 ? 100 : $pct;
 		echo "<h2>" . htmlentities($home_info['home_name']) . "</h2>";
 		echo '<div class="dragbox bloc rounded" style="background-color:#dce9f2;" >
-				<h4>'.get_lang('install')." ".$filename." ${mbytes}MB/${totalmbytes}MB</h4>
+				<h4>'.get_lang('install')." ".$filename." " . $mbytes . "MB/" . $totalmbytes . "MB</h4>
 			  <div style='background-color:#dce9f2;' >
 			  ";
 		$bar = '';

+ 1 - 1
modules/gamemanager/rsync_install.php

@@ -307,7 +307,7 @@ function exec_ogp_module() {
 			list($totalsize,$mbytes,$pct) = explode(";",do_progress($kbytes,$lgslname."/".$os));
 			$totalmbytes = round($totalsize / 1024, 2);
 			echo '<div class="dragbox bloc rounded" style="background-color:#dce9f2;" >
-					<h4>'. get_lang("update_in_progress") ." ${mbytes}MB/${totalmbytes}MB</h4>
+					<h4>'. get_lang("update_in_progress") ." " . $mbytes . "MB/" . $totalmbytes . "MB</h4>
 				  <div style='background-color:#dce9f2;' >
 				  ";
 			$bar = '';

+ 1 - 1
modules/gamemanager/update_server_manual.php

@@ -104,7 +104,7 @@ function exec_ogp_module() {
 		$totalmbytes = round($totalsize / 1024, 2);
 		$pct = $pct > 100 ? 100 : $pct;
 		echo '<div class="dragbox bloc rounded" style="background-color:#dce9f2;" >
-				<h4>'. get_lang("update_in_progress") ." ${mbytes}MB/${totalmbytes}MB</h4>
+				<h4>'. get_lang("update_in_progress") ." " . $mbytes . "MB/" . $totalmbytes . "MB</h4>
 			  <div style='background-color:#dce9f2;' >
 			  ";
 		$bar = '';

+ 2 - 2
modules/litefm/fm_dir.php

@@ -214,7 +214,7 @@ function exec_ogp_module()
 			{
 				$remote->shell_action('remove_recursive', $files);
 				$files = str_replace('" "','"<br>"',$files);
-				$db->logger( get_lang("remove") . ": ${files}" );
+				$db->logger( get_lang("remove") . ": " . $files );
 			}
 		}
 	}
@@ -349,7 +349,7 @@ function exec_ogp_module()
 		if($items != '')
 		{
 			$retval = $remote->compress_files($items,$path,$archive_name,$archive_type);
-			$archive = clean_path( "${path}/${archive_name}.${archive_type}" );
+			$archive = clean_path( $path . "/" . $archive_name . "." . $archive_type );
 			if( $retval == 0 )
 			{
 				do{

+ 10 - 10
modules/update/unzip.php

@@ -29,18 +29,18 @@ function extractZip( $zipFile, $extract_path, $remove_path = '', $blacklist = ''
 
 	if(!file_exists($extract_path))
 	{
-		return "Destination path (${extract_path}) does not exists.\n";
+		return "Destination path (" . $extract_path . ") does not exists.\n";
 	}
 
 	if(!is_writable($extract_path))
 	{
-		return "Can't extract to ${extract_path}, not writable.\n";
+		return "Can't extract to " . $extract_path . ", not writable.\n";
 	}
 
 	if($zipFile == '' or $extract_path == '')
 		return "Invalid arguments.\n";
 	if( ! file_exists( $zipFile ) )
-		return "Unable to read ${zipFile}.\n";
+		return "Unable to read " . $zipFile . ".\n";
 	$remove_path = addcslashes($remove_path,"/");
 
 	$zip = new ZipArchive; 
@@ -91,7 +91,7 @@ function extractZip( $zipFile, $extract_path, $remove_path = '', $blacklist = ''
 							{
 								if(!mkdir($tmp, 0777))
 								{
-									return "Unable to write folder ${tmp}.\n";
+									return "Unable to write folder " . $tmp . ".\n";
 								}
 							}
 						}
@@ -114,7 +114,7 @@ function extractZip( $zipFile, $extract_path, $remove_path = '', $blacklist = ''
 						}
 						else
 						{
-							return "Unable to write file ${completeName}.\n";
+							return "Unable to write file " . $completeName . ".\n";
 						}
 					}
 				}
@@ -123,7 +123,7 @@ function extractZip( $zipFile, $extract_path, $remove_path = '', $blacklist = ''
 		}
 		return array('ignored_files' => $ignored_files, 'extracted_files' => $extracted_files);
 	}
-	return "${zipFile} is corrupt.\n";
+	return $zipFile . " is corrupt.\n";
 }
 
 function extractZipGitUpdateFile( $zipFile, $extract_path)
@@ -131,18 +131,18 @@ function extractZipGitUpdateFile( $zipFile, $extract_path)
 
 	if(!file_exists($extract_path))
 	{
-		return "Destination path (${extract_path}) does not exists.\n";
+		return "Destination path (" . $extract_path . ") does not exists.\n";
 	}
 
 	if(!is_writable($extract_path))
 	{
-		return "Can't extract to ${extract_path}, not writable.\n";
+		return "Can't extract to " . $extract_path . ", not writable.\n";
 	}
 
 	if($zipFile == '' or $extract_path == '')
 		return "Invalid arguments.\n";
 	if( ! file_exists( $zipFile ) )
-		return "Unable to read ${zipFile}.\n";
+		return "Unable to read " . $zipFile . ".\n";
 
 	$zip = new ZipArchive; 
 	if ($zip)
@@ -177,6 +177,6 @@ function extractZipGitUpdateFile( $zipFile, $extract_path)
 		
 		return array('ignored_files' => $ignored_files, 'extracted_files' => $extracted_files);
 	}
-	return "${zipFile} is corrupt.\n";
+	return $zipFile . " is corrupt.\n";
 }
 ?>

+ 10 - 2
modules/user_admin/add_group.php

@@ -30,17 +30,25 @@ function exec_ogp_module()
     if( isset($_POST['add_group']) )
     {
         $group = sanitizeInputStr($_POST['group_name']);
+        $groupWithSameName = $db->getGroupByName($group);
 
         if (empty($group))
         {
             print_failure(get_lang('group_name_empty'));
             return;
         }
-
+		
+		if ($groupWithSameName !== false && is_array($groupWithSameName) && count($groupWithSameName) > 0)
+        {
+            print_failure(get_lang_f("failed_to_add_group_exists_already",$group));
+            $view->refresh("?m=user_admin&amp;p=show_groups", 5);
+            return;
+        }
+		
         if ( !$db->addGroup($group,$_SESSION['user_id']) )
         {
             print_failure(get_lang_f("failed_to_add_group",$group));
-            $view->refresh("?m=user_admin&amp;p=show_groups");
+            $view->refresh("?m=user_admin&amp;p=show_groups", 5);
             return;
         }