Changeset 1121
- Timestamp:
- Apr 5, 2006, 12:29:35 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/cat_modify.php
r1082 r1121 115 115 116 116 // Link the new category to the current category 117 $query = ' 118 INSERT 119 INTO '.CATEGORIES_LINK_TABLE.' 120 (source, destination) 121 VALUES 122 ('.$_GET['cat_id'].', '.$output_create['id'].') 123 ;'; 124 pwg_query($query); 125 126 check_links(array($output_create['id'])); 127 update_category(array($output_create['id'])); 128 } 129 } 130 else if (isset($_POST['destination_trueify']) 131 and isset($_POST['destination_false']) 132 and count($_POST['destination_false'])) 133 { 134 $datas = array(); 135 136 foreach ($_POST['destination_false'] as $category_id) 137 { 117 associate_categories_to_categories( 118 array($_GET['cat_id']), 119 array($output_create['id']) 120 ); 121 122 // information 138 123 array_push( 139 $datas, 140 array( 141 'source' => $_GET['cat_id'], 142 'destination' => $category_id, 124 $page['infos'], 125 sprintf( 126 l10n('Category elements associated to the following categories: %s'), 127 '<ul><li>' 128 .get_cat_display_name_from_id($output_create['id']) 129 .'</li></ul>' 143 130 ) 144 131 ); 145 132 } 146 147 mass_inserts( 148 CATEGORIES_LINK_TABLE, 149 array('source', 'destination'), 150 $datas 151 ); 152 153 check_links($_POST['destination_false']); 154 update_category( 155 $_POST['destination_false'], 156 true // recursive update 157 ); 158 } 159 else if (isset($_POST['destination_falsify']) 160 and isset($_POST['destination_true']) 161 and count($_POST['destination_true'])) 162 { 163 foreach ($_POST['destination_true'] as $destination) 164 { 165 delete_sources($destination, array($_GET['cat_id'])); 166 } 167 168 update_category( 169 $_POST['destination_true'], 170 true // recursive update 171 ); 172 } 173 else if (isset($_POST['source_trueify']) 174 and isset($_POST['source_false']) 175 and count($_POST['source_false'])) 176 { 177 $datas = array(); 178 179 foreach ($_POST['source_false'] as $category_id) 133 } 134 else if (isset($_POST['submitDestinations']) 135 and isset($_POST['destinations']) 136 and count($_POST['destinations']) > 0) 137 { 138 associate_categories_to_categories( 139 array($_GET['cat_id']), 140 $_POST['destinations'] 141 ); 142 143 $category_names = array(); 144 foreach ($_POST['destinations'] as $category_id) 180 145 { 181 146 array_push( 182 $datas, 183 array( 184 'source' => $category_id, 185 'destination' => $_GET['cat_id'], 186 ) 187 ); 188 } 189 190 mass_inserts( 191 CATEGORIES_LINK_TABLE, 192 array('source', 'destination'), 193 $datas 194 ); 195 196 check_links(array($_GET['cat_id'])); 197 update_category( 198 array($_GET['cat_id']), 199 true // recursive update 200 ); 201 } 202 else if (isset($_POST['source_falsify']) 203 and isset($_POST['source_true']) 204 and count($_POST['source_true'])) 205 { 206 delete_sources($_GET['cat_id'], $_POST['source_true']); 207 208 update_category( 209 array($_GET['cat_id']), 210 true // recursive update 211 ); 212 } 213 147 $category_names, 148 get_cat_display_name_from_id($category_id) 149 ); 150 } 151 152 array_push( 153 $page['infos'], 154 sprintf( 155 l10n('Category elements associated to the following categories: %s'), 156 '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>' 157 ) 158 ); 159 } 214 160 215 161 $query = ' … … 382 328 } 383 329 384 if (!$category['is_virtual']) //!empty($category['dir']))330 if (!$category['is_virtual']) 385 331 { 386 332 $template->assign_block_vars( … … 470 416 // destination categories 471 417 $query = ' 472 SELECT DISTINCT id, name, uppercats,global_rank418 SELECT id,name,uppercats,global_rank 473 419 FROM '.CATEGORIES_TABLE.' 474 INNER JOIN '.CATEGORIES_LINK_TABLE.' ON destination = id 475 WHERE source = '.$_GET['cat_id'].' 476 ;'; 477 display_select_cat_wrapper($query, array(), 'destination_option_true'); 478 479 // non destination categories 480 $destinations = array_merge( 481 array($_GET['cat_id']), 482 array_from_query($query, 'id') 420 WHERE id != '.$category['id'].' 421 ;'; 422 423 display_select_cat_wrapper( 424 $query, 425 array(), 426 'category_option_destination' 483 427 ); 484 428 485 $query = '486 SELECT DISTINCT id, name, uppercats, global_rank487 FROM '.CATEGORIES_TABLE.'488 WHERE id NOT IN ('.implode(',', $destinations).')489 ;';490 display_select_cat_wrapper($query, array(), 'destination_option_false');491 492 // source categories493 $query = '494 SELECT DISTINCT id, name, uppercats, global_rank495 FROM '.CATEGORIES_TABLE.'496 INNER JOIN '.CATEGORIES_LINK_TABLE.' ON source = id497 WHERE destination = '.$_GET['cat_id'].'498 ;';499 display_select_cat_wrapper($query, array(), 'source_option_true');500 501 // non source categories502 $sources = array_merge(503 array($_GET['cat_id']),504 array_from_query($query, 'id')505 );506 507 $query = '508 SELECT DISTINCT id, name, uppercats, global_rank509 FROM '.CATEGORIES_TABLE.'510 WHERE id NOT IN ('.implode(',', $sources).')511 ;';512 display_select_cat_wrapper($query, array(), 'source_option_false');513 429 514 430 //----------------------------------------------------------- sending html code -
trunk/admin/element_set_global.php
r1120 r1121 96 96 if ($_POST['associate'] != 0 and count($collection) > 0) 97 97 { 98 $datas = array(); 99 98 associate_images_to_categories( 99 $collection, 100 array($_POST['associate']) 101 ); 102 } 103 104 if ($_POST['dissociate'] != 0 and count($collection) > 0) 105 { 106 // physical links must not be broken, so we must first retrieve image_id 107 // which create virtual links with the category to "dissociate from". 100 108 $query = ' 101 SELECT i mage_id109 SELECT id 102 110 FROM '.IMAGE_CATEGORY_TABLE.' 103 WHERE category_id = '.$_POST['associate'].' 104 ;'; 105 $associated = array_from_query($query, 'image_id'); 106 107 $associable = array_diff($collection, $associated); 108 109 if (count($associable) != 0) 110 { 111 foreach ($associable as $item) 112 { 113 array_push( 114 $datas, 115 array( 116 'category_id' => $_POST['associate'], 117 'image_id' => $item 118 ) 119 ); 120 } 121 122 mass_inserts( 123 IMAGE_CATEGORY_TABLE, 124 array('image_id', 'category_id'), 125 $datas 126 ); 127 128 check_links(); 129 update_category(array($_POST['associate'])); 130 } 131 } 132 133 if ($_POST['dissociate'] != 0 and count($collection) > 0) 134 { 135 // First, we must identify which elements in the collection are really 136 // virtually associated with the category 137 $query = ' 138 SELECT image_id 139 FROM '.IMAGE_CATEGORY_TABLE.' 111 INNER JOIN '.IMAGES_TABLE.' ON image_id = id 140 112 WHERE category_id = '.$_POST['dissociate'].' 141 AND image_id IN ('.implode(',', $collection).') 142 AND is_storage = \'false\' 143 ;'; 144 $associated_images = array_from_query($query, 'image_id'); 145 146 // If the same element is associated to a source and its destinations, 147 // dissociating the element with the source implies dissociating the 148 // element fwith the destination. 149 $destinations_of = get_destinations($_POST['dissociate']); 150 151 $associated_categories = array_merge( 152 array($_POST['dissociate']), 153 $destinations_of[ $_POST['dissociate'] ] 154 ); 155 156 // Eventually, deletion of associations 113 AND id IN ('.implode(',', $collection).') 114 AND category_id != storage_category_id 115 ;'; 116 $dissociables = array_from_query($query, 'id'); 117 157 118 $query = ' 158 119 DELETE 159 120 FROM '.IMAGE_CATEGORY_TABLE.' 160 WHERE category_id IN ('.implode(',', $associated_categories).'161 AND image_id IN ('.implode(',', $ associated_images).')121 WHERE category_id = '.$_POST['dissociate'].' 122 AND image_id IN ('.implode(',', $dissociables).') 162 123 '; 163 124 pwg_query($query); 164 165 // check source/destination links. If category C has for sources A and 166 // B, if picture 1 was associated to A and B, the previous code lines 167 // have deleted the link between C and 1, while it should be kept due to 168 // B. Who said "complicated"? 169 check_links(); 170 171 update_category($associated_categories); 125 126 update_category($_POST['dissociate']); 172 127 } 173 128 … … 319 274 AND ic.category_id = c.id 320 275 AND ic.image_id = i.id 321 AND ic. is_storage = \'false\'276 AND ic.category_id != i.storage_category_id 322 277 ;'; 323 278 display_select_cat_wrapper($query, array(), $blockname, true); -
trunk/admin/include/functions.php
r1119 r1121 153 153 // destruction of all the related elements 154 154 $query = ' 155 SELECT image_id 156 FROM '.IMAGE_CATEGORY_TABLE.' 157 WHERE is_storage = \'true\' 158 AND category_id IN ('. 159 wordwrap( 160 implode(', ', $ids), 161 80, 162 "\n" 163 ). 164 ') 155 SELECT id 156 FROM '.IMAGES_TABLE.' 157 WHERE storage_category_id IN ( 158 '.wordwrap(implode(', ', $ids), 80, "\n").') 165 159 ;'; 166 160 $result = pwg_query($query); … … 168 162 while ($row = mysql_fetch_array($result)) 169 163 { 170 array_push($element_ids, $row['i mage_id']);164 array_push($element_ids, $row['id']); 171 165 } 172 166 delete_elements($element_ids); … … 194 188 ;'; 195 189 pwg_query($query); 196 197 // source/destination links deletion198 $query = '199 SELECT destination, source200 FROM '.CATEGORIES_LINK_TABLE.'201 WHERE source IN ('.implode(',', $ids).')202 OR destination IN ('.implode(',', $ids).')203 ;';204 $result = pwg_query($query);205 206 $sources_of = array();207 208 while ($row = mysql_fetch_array($result))209 {210 if (!isset($sources_of[ $row['destination'] ]))211 {212 $sources_of[ $row['destination'] ] = array();213 }214 215 array_push(216 $sources_of[ $row['destination'] ],217 $row['source']218 );219 }220 221 foreach ($sources_of as $destination => $sources)222 {223 delete_sources($destination, $sources);224 }225 226 update_category();227 190 228 191 // destruction of the category … … 442 405 COUNT(image_id) AS nb_images, 443 406 MAX(date_available) AS date_last 444 FROM '.IMAGES_TABLE.' 445 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id 407 FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id 446 408 WHERE category_id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").') 447 409 GROUP BY category_id … … 450 412 $datas = array(); 451 413 $query_ids = array(); 452 while ( $row = mysql_fetch_array($result))414 while ( $row = mysql_fetch_array( $result ) ) 453 415 { 454 416 array_push($query_ids, $row['category_id']); … … 467 429 foreach (array_diff($cat_ids, $query_ids) as $id) 468 430 { 469 array_push( 470 $datas, 471 array( 472 'id' => $id, 473 'nb_images' => 0, 474 ) 475 ); 476 } 477 478 mass_updates( 479 CATEGORIES_TABLE, 480 array( 481 'primary' => array('id'), 482 'update' => array('date_last', 'nb_images') 483 ), 484 $datas 485 ); 431 array_push($datas, array('id' => $id, 'nb_images' => 0)); 432 } 433 434 $fields = array('primary' => array('id'), 435 'update' => array('date_last', 'nb_images')); 436 mass_updates(CATEGORIES_TABLE, $fields, $datas); 486 437 487 438 // representative pictures … … 1358 1309 function update_path() 1359 1310 { 1360 $images_of = array(); 1361 1362 $query = ' 1363 SELECT category_id, image_id 1364 FROM '.IMAGE_CATEGORY_TABLE.' 1365 WHERE is_storage = \'true\' 1366 ;'; 1367 $result = pwg_query($query); 1368 while ($row = mysql_fetch_array($result)) 1369 { 1370 if (!isset($images_of[ $row['category_id'] ])) 1371 { 1372 $images_of[ $row['category_id'] ] = array(); 1373 } 1374 1375 array_push( 1376 $images_of[ $row['category_id'] ], 1377 $row['image_id'] 1378 ); 1379 } 1380 1381 $fulldirs = get_fulldirs( 1382 array_keys($images_of) 1383 ); 1384 1385 foreach ($images_of as $cat_id => $image_ids) 1311 $query = ' 1312 SELECT DISTINCT(storage_category_id) 1313 FROM '.IMAGES_TABLE.' 1314 ;'; 1315 $cat_ids = array_from_query($query, 'storage_category_id'); 1316 $fulldirs = get_fulldirs($cat_ids); 1317 1318 foreach ($cat_ids as $cat_id) 1386 1319 { 1387 1320 $query = ' 1388 1321 UPDATE '.IMAGES_TABLE.' 1389 1322 SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file) 1390 WHERE id IN ('. 1391 wordwrap( 1392 implode(', ', $image_ids), 1393 80, 1394 "\n"). 1395 ') 1323 WHERE storage_category_id = '.$cat_id.' 1396 1324 ;'; 1397 1325 pwg_query($query); … … 1614 1542 1615 1543 /** 1616 * Returns all destinations of a list of source categories. This function1617 * solves transitivity.1618 *1619 * @param mixed array of category ids, empty for all categories1620 */1621 function get_destinations($categories = 'all')1622 {1623 $query = '1624 SELECT source, destination1625 FROM '.CATEGORIES_LINK_TABLE.'1626 ';1627 $result = pwg_query($query);1628 1629 $destinations_of = array();1630 1631 while ($row = mysql_fetch_array($result))1632 {1633 if (!isset($destinations_of[ $row['source'] ]))1634 {1635 $destinations_of[ $row['source'] ] = array();1636 }1637 1638 array_push(1639 $destinations_of[ $row['source'] ],1640 $row['destination']1641 );1642 }1643 1644 // transitivity resolution: if " => " means "source of", if A=>B=>C1645 // implies A=>B and A=>C. So A has 2 destinations: B and C.1646 do1647 {1648 // let's suppose we only need a single turn1649 $need_new_turn = false;1650 1651 foreach ($destinations_of as $source => $destinations)1652 {1653 foreach ($destinations as $destination)1654 {1655 // does the current destination has destinations itself?1656 if (isset($destinations_of[$destination]))1657 {1658 // are there destinations of current destination not already among1659 // destinations of the current source? (advise: take a piece of1660 // paper and draw a schema). The source itself must not be counted1661 // as a destination, thus avoiding cyclic links.1662 $missing_destinations = array_diff(1663 $destinations_of[$destination],1664 $destinations,1665 array($source) // no cyclic link1666 );1667 1668 if (count($missing_destinations) > 0)1669 {1670 $destinations_of[$source] = array_unique(1671 array_merge(1672 $destinations,1673 $missing_destinations1674 )1675 );1676 1677 // a category has a least one new destination, we have to check1678 // one more time that it doesn't generate more destinations1679 $need_new_turn = true;1680 }1681 }1682 }1683 }1684 } while ($need_new_turn);1685 1686 if (is_array($categories))1687 {1688 $filtered_destinations_of = array();1689 1690 // Even if there is no destinations for the requested categories, we1691 // return empty arrays1692 foreach ($categories as $category)1693 {1694 $filtered_destinations_of[$category] = array();1695 }1696 1697 foreach ($destinations_of as $source => $destinations)1698 {1699 if (in_array($source, $categories))1700 {1701 $filtered_destinations_of[$source] = $destinations;1702 }1703 }1704 1705 return $filtered_destinations_of;1706 }1707 else1708 {1709 return $destinations_of;1710 }1711 }1712 1713 /**1714 * Returns all sources of a list of destination categories. This function1715 * solves transitivity.1716 *1717 * @param mixed array of category ids, empty for all categories1718 */1719 function get_sources($categories = 'all')1720 {1721 $destinations_of = get_destinations();1722 1723 $sources_of = array();1724 1725 foreach ($destinations_of as $source => $destinations)1726 {1727 foreach ($destinations as $destination)1728 {1729 if (!isset($sources_of[$destination]))1730 {1731 $sources_of[$destination] = array();1732 }1733 1734 array_push($sources_of[$destination], $source);1735 }1736 }1737 1738 // eventually, filter1739 if (is_array($categories))1740 {1741 $filtered_sources_of = array();1742 1743 // Even if there is no sources for the requested categories, we return1744 // empty arrays1745 foreach ($categories as $category)1746 {1747 $filtered_sources_of[$category] = array();1748 }1749 1750 foreach ($sources_of as $destination => $sources)1751 {1752 if (in_array($destination, $categories))1753 {1754 $filtered_sources_of[$destination] = $sources;1755 }1756 }1757 1758 return $filtered_sources_of;1759 }1760 else1761 {1762 return $sources_of;1763 }1764 }1765 1766 /**1767 * Checks categories links are respected for a given list of destinations.1768 *1769 * Checking categories links means that each destination must be associated1770 * to the images of its sources.1771 *1772 * @param mixed source category ids1773 */1774 function check_links($destinations = 'all')1775 {1776 $sources_of = get_sources($destinations);1777 1778 if (empty($sources_of))1779 {1780 return true;1781 }1782 1783 // we need to search images of all sources and destinations1784 $images_of = array();1785 1786 foreach ($sources_of as $destination => $sources)1787 {1788 $images_of[$destination] = array();1789 1790 foreach ($sources as $source)1791 {1792 $images_of[$source] = array();1793 }1794 }1795 1796 $query = '1797 SELECT image_id, category_id1798 FROM '.IMAGE_CATEGORY_TABLE.'1799 WHERE category_id IN ('.1800 implode(',', array_keys($images_of)).1801 ')1802 ;';1803 $result = pwg_query($query);1804 1805 while ($row = mysql_fetch_array($result))1806 {1807 array_push(1808 $images_of[ $row['category_id'] ],1809 $row['image_id']1810 );1811 }1812 1813 $inserts = array();1814 1815 foreach ($sources_of as $destination => $sources)1816 {1817 // merge all images from the sources of this destination1818 $sources_images = array();1819 1820 foreach ($sources as $source)1821 {1822 $sources_images = array_merge(1823 $sources_images,1824 $images_of[$source]1825 );1826 }1827 1828 $sources_images = array_unique($sources_images);1829 1830 // are there images among the sources that are not linked to the1831 // destination?1832 $missing_images = array_diff(1833 $sources_images,1834 $images_of[$destination]1835 );1836 1837 // if we find missing images (missing links in reality), we prepare the1838 // final mass_inserts1839 if (count($missing_images) > 0)1840 {1841 foreach ($missing_images as $missing_image)1842 {1843 array_push(1844 $inserts,1845 array(1846 'category_id' => $destination,1847 'image_id' => $missing_image,1848 )1849 );1850 }1851 }1852 }1853 1854 if (count($inserts) > 0)1855 {1856 mass_inserts(1857 IMAGE_CATEGORY_TABLE,1858 array_keys($inserts[0]),1859 $inserts1860 );1861 }1862 }1863 1864 /**1865 * Based on categories links, delete image_category links on destinations.1866 *1867 * The rule is the following: if an image belong to the category and to the1868 * source, we suppose it comes from the source. If the source/destination1869 * link is broken, we delete the image/category link if the only origin of1870 * the link was the broken categories link.1871 *1872 * Example: "=>" means "source of". Between brackets the associated images.1873 *1874 * A (1,2,9) => \1875 * |=> C (1,2,3,4,5,9) => D (1,2,3,4,5,6,9)1876 * B (3,4,9) => /1877 *1878 * In category C, we suppose (1,2) come from A, (3,4) from B, 9 from A or B1879 * and 5 was manually added. In category D, 6 was added manually.1880 *1881 * If we break A=>C, C and D loose (1,2) but not 9 because it can come from1882 * B. If we break C=>D, D loose (3,4,5,9) but not 6 because it was1883 * associated manually to 9.1884 *1885 * Warning: only virtual links can be removed, physical links are protected.1886 *1887 * @param int destination1888 * @param array sources1889 */1890 function delete_sources($destination, $sources)1891 {1892 // if no sources to unlink, we stop with OK status1893 if (count($sources) == 0)1894 {1895 return true;1896 }1897 1898 $query = '1899 DELETE1900 FROM '.CATEGORIES_LINK_TABLE.'1901 WHERE destination = '.$destination.'1902 AND source IN ('.implode(',', $sources).')1903 ;';1904 pwg_query($query);1905 1906 // The strategy is the following:1907 //1908 // * first we brutally delete the image/category associations on1909 // destinations categories for all images belonging to sources.1910 //1911 // * then we check_links on destinations to rebuild missing image/category1912 // associations.1913 1914 // what are the images associated to the sources to unlink1915 $query = '1916 SELECT image_id1917 FROM '.IMAGE_CATEGORY_TABLE.'1918 WHERE category_id IN ('.1919 implode(',', $sources).1920 ')1921 ;';1922 $sources_images = array_unique(1923 array_from_query($query, 'image_id')1924 );1925 1926 if (count($sources_images) == 0)1927 {1928 return true;1929 }1930 1931 // retrieve all direct and indirect destinations of the current1932 // destination1933 $destinations_of = get_destinations(array($destination));1934 1935 $destinations = array_merge(1936 array($destination),1937 $destinations_of[$destination]1938 );1939 1940 // unlink sources images from destinations1941 $query = '1942 DELETE1943 FROM '.IMAGE_CATEGORY_TABLE.'1944 WHERE category_id IN ('.implode(',', $destinations).')1945 AND image_id IN ('.implode(',', $sources_images).')1946 AND is_storage = \'false\'1947 ;';1948 pwg_query($query);1949 1950 // if the representative thumbnail of destinations was a picture from1951 // $sources_images, we request a new random representant1952 $query = '1953 SELECT id, representative_picture_id1954 FROM '.CATEGORIES_TABLE.'1955 WHERE id IN ('.implode(',', $destinations).')1956 ;';1957 $result = pwg_query($query);1958 1959 $request_random = array();1960 1961 while ($row = mysql_fetch_array($result))1962 {1963 if (isset($row['representative_picture_id']))1964 {1965 if (in_array($row['representative_picture_id'], $sources_images))1966 {1967 array_push($request_random, $row['id']);1968 }1969 }1970 }1971 1972 set_random_representant($request_random);1973 1974 // eventually, we check_links to rebuild missing associations1975 check_links($destinations);1976 1977 return true;1978 }1979 1980 /**1981 1544 * create a virtual category 1982 1545 * … … 2300 1863 2301 1864 } 1865 1866 /** 1867 * Associate a list of images to a list of categories. 1868 * 1869 * The function will not duplicate links 1870 * 1871 * @param array images 1872 * @param array categories 1873 * @return void 1874 */ 1875 function associate_images_to_categories($images, $categories) 1876 { 1877 if (count($images) == 0 1878 or count($categories) == 0) 1879 { 1880 return false; 1881 } 1882 1883 $query = ' 1884 DELETE 1885 FROM '.IMAGE_CATEGORY_TABLE.' 1886 WHERE image_id IN ('.implode(',', $images).') 1887 AND category_id IN ('.implode(',', $categories).') 1888 ;'; 1889 pwg_query($query); 1890 1891 $inserts = array(); 1892 foreach ($categories as $category_id) 1893 { 1894 foreach ($images as $image_id) 1895 { 1896 array_push( 1897 $inserts, 1898 array( 1899 'image_id' => $image_id, 1900 'category_id' => $category_id, 1901 ) 1902 ); 1903 } 1904 } 1905 1906 mass_inserts( 1907 IMAGE_CATEGORY_TABLE, 1908 array_keys($inserts[0]), 1909 $inserts 1910 ); 1911 1912 update_category($categories); 1913 } 1914 1915 /** 1916 * Associate images associated to a list of source categories to a list of 1917 * destination categories. 1918 * 1919 * @param array sources 1920 * @param array destinations 1921 * @return void 1922 */ 1923 function associate_categories_to_categories($sources, $destinations) 1924 { 1925 if (count($sources) == 0) 1926 { 1927 return false; 1928 } 1929 1930 $query = ' 1931 SELECT image_id 1932 FROM '.IMAGE_CATEGORY_TABLE.' 1933 WHERE category_id IN ('.implode(',', $sources).') 1934 ;'; 1935 $images = array_from_query($query, 'image_id'); 1936 1937 associate_images_to_categories($images, $destinations); 1938 } 2302 1939 ?> -
trunk/admin/include/functions_metadata.php
r1119 r1121 247 247 SELECT id, path 248 248 FROM '.IMAGES_TABLE.' 249 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id 250 WHERE is_storage = \'true\' 251 AND category_id IN ('.implode(',', $cat_ids).')'; 249 WHERE storage_category_id IN ('.implode(',', $cat_ids).')'; 252 250 if ($only_new) 253 251 { -
trunk/admin/maintenance.php
r1111 r1121 48 48 case 'categories' : 49 49 { 50 check_links();51 50 update_uppercats(); 52 51 update_category('all'); -
trunk/admin/picture_modify.php
r1119 r1121 122 122 and count($_POST['cat_dissociated']) > 0) 123 123 { 124 $datas = array(); 125 126 foreach ($_POST['cat_dissociated'] as $category_id) 127 { 128 array_push( 129 $datas, 130 array( 131 'image_id' => $_GET['image_id'], 132 'category_id' => $category_id 133 ) 134 ); 135 } 136 137 mass_inserts( 138 IMAGE_CATEGORY_TABLE, 139 array('image_id', 'category_id'), 140 $datas 124 associate_images_to_categories( 125 array($_GET['image_id']), 126 $_POST['cat_dissociated'] 141 127 ); 142 143 check_links();144 update_category($_POST['cat_dissociated']);145 128 } 146 129 // dissociate the element from categories (but not from its storage category) … … 149 132 and count($_POST['cat_associated']) > 0) 150 133 { 151 $associated_categories = $_POST['cat_associated'];152 153 // If the same element is associated to a source and its destinations,154 // dissociating the element with the source implies dissociating the155 // element fwith the destination.156 $destinations_of = get_destinations($_POST['cat_associated']);157 foreach ($destinations_of as $source => $destinations)158 {159 $associated_categories = array_merge(160 $associated_categories,161 $destinations162 );163 }164 165 134 $query = ' 166 135 DELETE FROM '.IMAGE_CATEGORY_TABLE.' 167 136 WHERE image_id = '.$_GET['image_id'].' 168 AND category_id IN ('.implode(',', $associated_categories).') 169 AND is_storage = \'false\' 137 AND category_id IN ('.implode(',', $_POST['cat_associated']).') 170 138 '; 171 139 pwg_query($query); 172 173 check_links(); 140 174 141 update_category($_POST['cat_associated']); 175 142 } … … 202 169 SELECT * 203 170 FROM '.IMAGES_TABLE.' 204 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id205 171 WHERE id = '.$_GET['image_id'].' 206 AND is_storage = \'true\'207 172 ;'; 208 173 $row = mysql_fetch_array(pwg_query($query)); 209 174 210 $storage_category_id = $row[' category_id'];175 $storage_category_id = $row['storage_category_id']; 211 176 $image_file = $row['file']; 212 177 … … 397 362 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id 398 363 WHERE image_id = '.$_GET['image_id'].' 399 AND i s_storage = \'false\'364 AND id != '.$storage_category_id.' 400 365 ;'; 401 366 display_select_cat_wrapper($query, array(), 'associated_option'); -
trunk/admin/rating.php
r1090 r1121 183 183 i.tn_ext, 184 184 i.average_rate, 185 i.storage_category_id, 185 186 MAX(r.date) AS recently_rated, 186 187 COUNT(r.rate) AS nb_rates, 187 188 SUM(r.rate) AS sum_rates, 188 ROUND(STD(r.rate),2) AS std_rates, 189 ic.category_id AS storage_category_id 189 ROUND(STD(r.rate),2) AS std_rates 190 190 FROM '.RATE_TABLE.' AS r 191 191 LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id 192 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id193 192 WHERE 1 = 1 ' . $display_filter . ' 194 AND ic.is_storage = \'true\'195 193 GROUP BY r.element_id 196 194 ORDER BY ' . $available_order_by[$order_by_index][1] .' -
trunk/admin/site_update.php
r1119 r1121 369 369 SELECT id, path 370 370 FROM '.IMAGES_TABLE.' 371 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id 372 WHERE is_storage = \'true\' 373 AND category_id IN ('. 374 wordwrap( 371 WHERE storage_category_id IN (' 372 .wordwrap( 375 373 implode(', ', $cat_ids), 376 374 80, 377 375 "\n" 378 ). 379 ') 376 ).') 380 377 ;'; 381 378 $result = pwg_query($query); … … 459 456 : null, 460 457 'path' => $path, 458 'storage_category_id' => $db_fulldirs[$dirname], 461 459 ); 462 460 … … 470 468 array( 471 469 'image_id' => $insert{'id'}, 472 'category_id' => $db_fulldirs[$dirname], 473 'is_storage' => 'true', 470 'category_id' => $insert['storage_category_id'], 474 471 ) 475 472 ); … … 509 506 ? $fs[$path]['representative_ext'] 510 507 : null, 508 'storage_category_id' => $db_fulldirs[$dirname], 511 509 ); 512 510 … … 520 518 array( 521 519 'image_id' => $insert{'id'}, 522 'category_id' => $db_fulldirs[$dirname], 523 'is_storage' => 'true', 520 'category_id' => $insert['storage_category_id'], 524 521 ) 525 522 ); … … 553 550 IMAGE_CATEGORY_TABLE, 554 551 array( 555 'image_id','category_id', 'is_storage',552 'image_id','category_id', 556 553 ), 557 554 $insert_links … … 610 607 SELECT id 611 608 FROM '.IMAGES_TABLE.' 612 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id 613 WHERE is_storage = \'true\' 614 AND category_id = '.$row['storage_category_id'].' 609 WHERE storage_category_id = '.$row['storage_category_id'].' 615 610 AND file = \''.$row['file'].'\' 616 611 ;'; … … 659 654 if (!$simulate) 660 655 { 661 $start = get_moment();662 check_links('all');663 echo '<!-- check_links(all) : ';664 echo get_elapsed_time($start,get_moment());665 echo ' -->'."\n";666 656 $start = get_moment(); 667 657 update_category('all'); -
trunk/include/constants.php
r1119 r1121 70 70 define('SEARCH_TABLE', $prefixeTable.'search'); 71 71 define('USER_MAIL_NOTIFICATION_TABLE', $prefixeTable.'user_mail_notification'); 72 define('CATEGORIES_LINK_TABLE', $prefixeTable.'categories_link');73 72 define('TAGS_TABLE', $prefixeTable.'tags'); 74 73 define('IMAGE_TAG_TABLE', $prefixeTable.'image_tag'); -
trunk/install/phpwebgallery_structure.sql
r1119 r1121 43 43 44 44 -- 45 -- Table structure for table `phpwebgallery_categories_link`46 --47 48 DROP TABLE IF EXISTS `phpwebgallery_categories_link`;49 CREATE TABLE `phpwebgallery_categories_link` (50 `source` smallint(5) unsigned NOT NULL default '0',51 `destination` smallint(5) unsigned NOT NULL default '0',52 PRIMARY KEY (`source`,`destination`)53 ) TYPE=MyISAM;54 55 --56 45 -- Table structure for table `phpwebgallery_comments` 57 46 -- … … 139 128 `image_id` mediumint(8) unsigned NOT NULL default '0', 140 129 `category_id` smallint(5) unsigned NOT NULL default '0', 141 `is_storage` enum('true','false') default 'false',142 130 PRIMARY KEY (`image_id`,`category_id`), 143 131 KEY `image_category_i1` (`image_id`), … … 179 167 `has_high` enum('true') default NULL, 180 168 `path` varchar(255) NOT NULL default '', 169 `storage_category_id` smallint(5) unsigned default NULL, 181 170 PRIMARY KEY (`id`), 182 171 KEY `images_i2` (`date_available`), -
trunk/language/en_UK.iso-8859-1/admin.lang.php
r1120 r1121 55 55 $lang['Categories manual order was saved'] = 'Categories manual order was saved'; 56 56 $lang['Categories ordered alphanumerically'] = 'Categories ordered alphanumerically'; 57 $lang['Category elements associated to the following categories: %s'] = 'Category elements associated to the following categories: %s'; 57 58 $lang['Check for upgrade failed for unknown reasons.'] = 'Check for upgrade failed for unknown reasons.'; 58 59 $lang['Check for upgrade'] = 'Check for upgrade'; … … 91 92 $lang['Interface theme'] = 'Interface theme'; 92 93 $lang['Language'] = 'Language'; 94 $lang['Link all category elements to a new category'] = 'Link all category elements to a new category'; 95 $lang['Link all category elements to some existing categories'] = 'Link all category elements to some existing categories'; 93 96 $lang['Linked categories'] = 'Linked categories'; 94 97 $lang['Lock gallery'] = 'Lock gallery'; … … 165 168 $lang['Virtual categories movement'] = 'Virtual categories movement'; 166 169 $lang['Virtual categories to move'] = 'Virtual categories to move'; 170 $lang['Virtual category name'] = 'Virtual category name'; 167 171 $lang['Webmaster cannot be deleted'] = 'Webmaster cannot be deleted'; 168 172 $lang['Yes'] = 'Yes'; -
trunk/language/fr_FR.iso-8859-1/admin.lang.php
r1119 r1121 56 56 $lang['Categories manual order was saved'] = 'L\'ordre manuel des catégories a été sauvegardé'; 57 57 $lang['Categories ordered alphanumerically'] = 'Catégories ordonnées alphabético-numériquement'; 58 $lang['Category elements associated to the following categories: %s'] = 'Les éléments de la catégorie ont été associés aux catégories suivantes : %s'; 58 59 $lang['Check for upgrade failed for unknown reasons.'] = 'La vérification de la dernière version sur le serveur a échouée pour une raison inconnue.'; 59 60 $lang['Check for upgrade'] = 'Dernière version ?'; … … 92 93 $lang['Interface theme'] = 'Theme de l\'interface'; 93 94 $lang['Language'] = 'Langue'; 95 $lang['Link all category elements to a new category'] = 'Associer tous les éléments de la catégorie à une nouvelle catégorie'; 96 $lang['Link all category elements to some existing categories'] = 'Associer tous les éléments de la catégorie à des catégories existantes'; 94 97 $lang['Linked categories'] = 'Catégories associées'; 95 98 $lang['Lock gallery'] = 'Verrouiller la galerie'; … … 166 169 $lang['Virtual categories movement'] = 'Déplacement de catégories virtuelles'; 167 170 $lang['Virtual categories to move'] = 'Catégories virtuelles à déplacer'; 171 $lang['Virtual category name'] = 'Nom de la catégorie virtuelle'; 168 172 $lang['Webmaster cannot be deleted'] = 'Le webmestre ne peut pas être supprimé'; 169 173 $lang['Yes'] = 'Oui'; -
trunk/template/yoga/admin/cat_modify.tpl
r1085 r1121 141 141 142 142 <fieldset> 143 <legend>{lang: Create a destinationcategory}</legend>143 <legend>{lang:Link all category elements to a new category}</legend> 144 144 145 145 <table> 146 146 <tr> 147 <td>{lang: virtual category name}</td>147 <td>{lang:Virtual category name}</td> 148 148 <td><input type="text" name="virtual_name"></td> 149 149 </tr> 150 150 151 151 <tr> 152 <td>{lang: parent category}</td>152 <td>{lang:Parent category}</td> 153 153 <td> 154 154 <select class="categoryList" name="parent"> … … 161 161 </table> 162 162 163 <p style="text-align:center;">163 <p> 164 164 <input type="submit" value="{lang:Submit}" name="submitAdd" {TAG_INPUT_ENABLED}/> 165 165 <input type="reset" value="{lang:Reset}" name="reset" /> … … 169 169 170 170 <fieldset> 171 <legend>{lang: Source/destination links}</legend>171 <legend>{lang:Link all category elements to some existing categories}</legend> 172 172 173 <table class="doubleSelect">173 <table> 174 174 <tr> 175 <td>{lang:Categories}</td> 175 176 <td> 176 <h3>{lang:Destination categories}</h3> 177 <select class="categoryList" name="destination_true[]" multiple="multiple" size="30"> 178 <!-- BEGIN destination_option_true --> 179 <option {destination_option_true.SELECTED} value="{destination_option_true.VALUE}">{destination_option_true.OPTION}</option> 180 <!-- END destination_option_true --> 177 <select class="categoryList" name="destinations[]" multiple="multiple" size="5"> 178 <!-- BEGIN category_option_destination --> 179 <option {category_option_destination.SELECTED} value="{category_option_destination.VALUE}">{category_option_destination.OPTION}</option> 180 <!-- END category_option_destination --> 181 181 </select> 182 <p><input type="submit" value="»" name="destination_falsify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>183 </td>184 185 <td>186 <h3>{lang:Non destination categories}</h3>187 <select class="categoryList" name="destination_false[]" multiple="multiple" size="30">188 <!-- BEGIN destination_option_false -->189 <option {destination_option_false.SELECTED} value="{destination_option_false.VALUE}">{destination_option_false.OPTION}</option>190 <!-- END destination_option_false -->191 </select>192 <p><input type="submit" value="«" name="destination_trueify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>193 182 </td> 194 183 </tr> 195 184 </table> 196 185 197 <table class="doubleSelect"> 198 <tr> 199 <td> 200 <h3>{lang:Source categories}</h3> 201 <select class="categoryList" name="source_true[]" multiple="multiple" size="30"> 202 <!-- BEGIN source_option_true --> 203 <option {source_option_true.SELECTED} value="{source_option_true.VALUE}">{source_option_true.OPTION}</option> 204 <!-- END source_option_true --> 205 </select> 206 <p><input type="submit" value="»" name="source_falsify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p> 207 </td> 186 <p> 187 <input type="submit" value="{lang:Submit}" name="submitDestinations" {TAG_INPUT_ENABLED}/> 188 <input type="reset" value="{lang:Reset}" name="reset" /> 189 </p> 208 190 209 <td>210 <h3>{lang:Non source categories}</h3>211 <select class="categoryList" name="source_false[]" multiple="multiple" size="30">212 <!-- BEGIN source_option_false -->213 <option {source_option_false.SELECTED} value="{source_option_false.VALUE}">{source_option_false.OPTION}</option>214 <!-- END source_option_false -->215 </select>216 <p><input type="submit" value="«" name="source_trueify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>217 </td>218 </tr>219 </table>220 221 191 </fieldset> 192 222 193 </form>
Note: See TracChangeset
for help on using the changeset viewer.