Commits

Anonymous committed 6dacbd7

Multi edit change category support for images, files and links

Comments (0)

Files changed (4)

textpattern/include/txp_file.php

 						n.'</ul>'
 					, 75).
 
-					td($file_statuses[$status], 45).
+					td(@$file_statuses[$status], 45).
 
 					td($condition, 45).
 
 		{
 			return file_delete($selected);
 		}
+		else if ($method == 'changecategory')
+		{
+			$category_name = gps('file');
+			
+			$cat_id = safe_field('id', 'txp_category', "type = 'file' and name = '" . doSlash($category_name) . "'");
+			if ($cat_id)
+			{				
+				$id_list = implode(', ', $selected);
 
-		if ($method == 'changecategory')
-		{
-			foreach ($selected as $id)
-			{
-				if (safe_update('txp_file', "category = '".doSlash(ps('category'))."'", "id = $id"))
+				// remove existing mappings
+				safe_delete('category_map', "type = 'file' and type_id in (".doSlash($id_list).") and category_id = $cat_id");
+				
+				if (gps('addremove') == 'add')
 				{
-					$changed[] = $id;
+					foreach ($selected as $id)
+					{
+						$id = assert_int($id);
+						if (safe_insert('category_map', "type = 'file', type_id = $id, category_id = $cat_id"))
+						{
+							$changed[] = $id;
+						}
+					}
 				}
 			}
 		}

textpattern/include/txp_image.php

 			return image_delete($selected);
 		}
 
-		if ($method == 'changecategory')
+		else if ($method == 'changecategory')
 		{
-			foreach ($selected as $id)
-			{
-				if(safe_update("category_map", "category_id = '$singlecat',type='image', type_id='$id'"))
+			$category_name = gps('image');
+			
+			$cat_id = safe_field('id', 'txp_category', "type = 'image' and name = '" . doSlash($category_name) . "'");
+			if ($cat_id)
+			{				
+				$id_list = implode(', ', $selected);
+
+				// remove existing mappings
+				safe_delete('category_map', "type = 'image' and type_id in (".doSlash($id_list).") and category_id = $cat_id");
+				
+				if (gps('addremove') == 'add')
 				{
-					$changed[] = $id;
+					foreach ($selected as $id)
+					{
+						$id = assert_int($id);
+						if (safe_insert('category_map', "type = 'image', type_id = $id, category_id = $cat_id"))
+						{
+							$changed[] = $id;
+						}
+					}
 				}
 			}
 		}

textpattern/include/txp_link.php

 		}
 		elseif ($method == 'changecategory')
 		{
-			foreach ($selected as $id)
-			{
-				if (safe_update('txp_link', "category = '".doSlash(ps('category'))."'", "id = $id"))
+			$category_name = gps('link');
+			
+			$cat_id = safe_field('id', 'txp_category', "type = 'link' and name = '" . doSlash($category_name) . "'");
+
+			if ($cat_id)
+			{				
+				$id_list = implode(', ', $selected);
+
+				// remove existing mappings
+				safe_delete('category_map', "type = 'link' and type_id in (".doSlash($id_list).") and category_id = $cat_id");
+				
+				if (gps('addremove') == 'add')
 				{
-					$changed[] = $id;
+					foreach ($selected as $id)
+					{
+						$id = assert_int($id);
+						if (safe_insert('category_map', "type = 'link', type_id = $id, category_id = $cat_id"))
+						{
+							$changed[] = $id;
+						}
+					}
 				}
 			}
 		}

textpattern/include/txp_list.php

 				case 'changecategory':
 					// prevent normal update processing
 					$category_name = gps('list');
-					$cat_id = safe_field('id', 'txp_category', "name = '".doSlash($category_name)."'",1);
+					$cat_id = safe_field('id', 'txp_category', "type = 'article' and name = '" . doSlash($category_name) . "'");
 
 					if (empty($cat_id))
 					{