Changeset 1064
- Timestamp:
- Mar 5, 2006, 12:31:46 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/cat_list.php
r1004 r1064 84 84 else if (isset($_POST['submitAdd'])) 85 85 { 86 // is the given category name only containing blank spaces ? 87 if (preg_match('/^\s*$/', $_POST['virtual_name'])) 88 { 89 array_push($page['errors'], $lang['cat_error_name']); 90 } 91 92 if (!count($page['errors'])) 93 { 94 $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL'; 95 96 if ($parent_id != 'NULL') 97 { 98 $query = ' 99 SELECT id,uppercats,global_rank,visible,status 100 FROM '.CATEGORIES_TABLE.' 101 WHERE id = '.$parent_id.' 102 ;'; 103 $row = mysql_fetch_array(pwg_query($query)); 104 $parent = array('id' => $row['id'], 105 'uppercats' => $row['uppercats'], 106 'visible' => $row['visible'], 107 'status' => $row['status'], 108 'global_rank' => $row['global_rank']); 109 } 110 111 // what will be the inserted id ? 112 $query = ' 113 SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) 114 FROM '.CATEGORIES_TABLE.' 115 ;'; 116 list($next_id) = mysql_fetch_array(pwg_query($query)); 117 118 $insert = array(); 119 $insert{'id'} = $next_id++; 120 $insert{'name'} = $_POST['virtual_name']; 121 $insert{'rank'} = $_POST['rank']; 122 $insert{'commentable'} = $conf['newcat_default_commentable']; 123 124 // a virtual category can't be uploadable 125 $insert{'uploadable'} = 'false'; 126 127 if (isset($parent)) 128 { 129 $insert{'id_uppercat'} = $parent{'id'}; 130 $insert{'uppercats'} = $parent{'uppercats'}.','.$insert{'id'}; 131 $insert{'global_rank'} = $parent{'global_rank'}.'.'.$insert{'rank'}; 132 // at creation, must a category be visible or not ? Warning : if 133 // the parent category is invisible, the category is automatically 134 // create invisible. (invisible = locked) 135 if ('false' == $parent['visible']) 136 { 137 $insert{'visible'} = 'false'; 138 } 139 else 140 { 141 $insert{'visible'} = $conf['newcat_default_visible']; 142 } 143 // at creation, must a category be public or private ? Warning : 144 // if the parent category is private, the category is 145 // automatically create private. 146 if ('private' == $parent['status']) 147 { 148 $insert{'status'} = 'private'; 149 } 150 else 151 { 152 $insert{'status'} = $conf['newcat_default_status']; 153 } 154 } 155 else 156 { 157 $insert{'visible'} = $conf['newcat_default_visible']; 158 $insert{'status'} = $conf['newcat_default_status']; 159 $insert{'uppercats'} = $insert{'id'}; 160 $insert{'global_rank'} = $insert{'rank'}; 161 } 162 163 $inserts = array($insert); 164 165 // we have then to add the virtual category 166 $dbfields = array('id','site_id','name','id_uppercat','rank', 167 'commentable','uploadable','visible','status', 168 'uppercats','global_rank'); 169 mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); 170 171 array_push($page['infos'], $lang['cat_virtual_added']); 86 $output_create = create_virtual_category( 87 $_POST['virtual_name'], 88 @$_GET['parent_id'] 89 ); 90 91 if (isset($output_create['error'])) 92 { 93 array_push($page['errors'], $output_create['error']); 94 } 95 else 96 { 97 array_push($page['infos'], $output_create['info']); 172 98 } 173 99 } … … 212 138 213 139 $current_category = get_cat_info($_GET['parent_id']); 214 $navigation.= get_cat_display_name($current_category['name'], 215 $base_url.'&parent_id=', 216 false); 140 141 $navigation.= get_cat_display_name( 142 $current_category['name'], 143 $base_url.'&parent_id=', 144 false 145 ); 217 146 } 218 147 // +-----------------------------------------------------------------------+ … … 227 156 } 228 157 229 if (count($categories) > 0)230 {231 $next_rank = max(array_keys($categories)) + 1;232 }233 else234 {235 $next_rank = 1;236 }237 238 158 $template->assign_vars(array( 239 159 'CATEGORIES_NAV'=>$navigation, 240 'NEXT_RANK'=>$next_rank,241 160 'F_ACTION'=>$form_action, 242 161 -
trunk/admin/cat_modify.php
r1058 r1064 89 89 pwg_query($query); 90 90 } 91 else if (isset($_POST['submitAdd'])) 92 { 93 $output_create = create_virtual_category( 94 $_POST['virtual_name'], 95 (0 == $_POST['parent'] ? null : $_POST['parent']) 96 ); 97 98 if (isset($output_create['error'])) 99 { 100 array_push($page['errors'], $output_create['error']); 101 } 102 else 103 { 104 // Virtual category creation succeeded 105 // 106 // Add the information in the information list 107 array_push($page['infos'], $output_create['info']); 108 109 // Link the new category to the current category 110 $query = ' 111 INSERT 112 INTO '.CATEGORIES_LINK_TABLE.' 113 (source, destination) 114 VALUES 115 ('.$_GET['cat_id'].', '.$output_create['id'].') 116 ;'; 117 pwg_query($query); 118 119 check_links(array($output_create['id'])); 120 update_category(array($output_create['id'])); 121 } 122 } 123 else if (isset($_POST['destination_trueify']) 124 and isset($_POST['destination_false']) 125 and count($_POST['destination_false'])) 126 { 127 $datas = array(); 128 129 foreach ($_POST['destination_false'] as $category_id) 130 { 131 array_push( 132 $datas, 133 array( 134 'source' => $_GET['cat_id'], 135 'destination' => $category_id, 136 ) 137 ); 138 } 139 140 mass_inserts( 141 CATEGORIES_LINK_TABLE, 142 array('source', 'destination'), 143 $datas 144 ); 145 146 check_links($_POST['destination_false']); 147 update_category( 148 $_POST['destination_false'], 149 true // recursive update 150 ); 151 } 152 else if (isset($_POST['destination_falsify']) 153 and isset($_POST['destination_true']) 154 and count($_POST['destination_true'])) 155 { 156 foreach ($_POST['destination_true'] as $destination) 157 { 158 delete_sources($destination, array($_GET['cat_id'])); 159 } 160 161 update_category( 162 $_POST['destination_true'], 163 true // recursive update 164 ); 165 } 166 else if (isset($_POST['source_trueify']) 167 and isset($_POST['source_false']) 168 and count($_POST['source_false'])) 169 { 170 $datas = array(); 171 172 foreach ($_POST['source_false'] as $category_id) 173 { 174 array_push( 175 $datas, 176 array( 177 'source' => $category_id, 178 'destination' => $_GET['cat_id'], 179 ) 180 ); 181 } 182 183 mass_inserts( 184 CATEGORIES_LINK_TABLE, 185 array('source', 'destination'), 186 $datas 187 ); 188 189 check_links(array($_GET['cat_id'])); 190 update_category( 191 array($_GET['cat_id']), 192 true // recursive update 193 ); 194 } 195 else if (isset($_POST['source_falsify']) 196 and isset($_POST['source_true']) 197 and count($_POST['source_true'])) 198 { 199 delete_sources($_GET['cat_id'], $_POST['source_true']); 200 201 update_category( 202 array($_GET['cat_id']), 203 true // recursive update 204 ); 205 } 206 91 207 92 208 $query = ' … … 317 433 } 318 434 435 $blockname = 'category_option_parent'; 436 437 $template->assign_block_vars( 438 $blockname, 439 array( 440 'VALUE'=> 0, 441 'OPTION' => '------------' 442 ) 443 ); 444 445 $query = ' 446 SELECT id,name,uppercats,global_rank 447 FROM '.CATEGORIES_TABLE.' 448 ;'; 449 450 display_select_cat_wrapper( 451 $query, 452 array(), 453 $blockname 454 ); 455 456 // destination categories 457 $query = ' 458 SELECT DISTINCT id, name, uppercats, global_rank 459 FROM '.CATEGORIES_TABLE.' 460 INNER JOIN '.CATEGORIES_LINK_TABLE.' ON destination = id 461 WHERE source = '.$_GET['cat_id'].' 462 ;'; 463 display_select_cat_wrapper($query, array(), 'destination_option_true'); 464 465 // non destination categories 466 $destinations = array_merge( 467 array($_GET['cat_id']), 468 array_from_query($query, 'id') 469 ); 470 471 $query = ' 472 SELECT DISTINCT id, name, uppercats, global_rank 473 FROM '.CATEGORIES_TABLE.' 474 WHERE id NOT IN ('.implode(',', $destinations).') 475 ;'; 476 display_select_cat_wrapper($query, array(), 'destination_option_false'); 477 478 // source categories 479 $query = ' 480 SELECT DISTINCT id, name, uppercats, global_rank 481 FROM '.CATEGORIES_TABLE.' 482 INNER JOIN '.CATEGORIES_LINK_TABLE.' ON source = id 483 WHERE destination = '.$_GET['cat_id'].' 484 ;'; 485 display_select_cat_wrapper($query, array(), 'source_option_true'); 486 487 // non source categories 488 $sources = array_merge( 489 array($_GET['cat_id']), 490 array_from_query($query, 'id') 491 ); 492 493 $query = ' 494 SELECT DISTINCT id, name, uppercats, global_rank 495 FROM '.CATEGORIES_TABLE.' 496 WHERE id NOT IN ('.implode(',', $sources).') 497 ;'; 498 display_select_cat_wrapper($query, array(), 'source_option_false'); 499 319 500 //----------------------------------------------------------- sending html code 320 501 $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); -
trunk/admin/include/functions.php
r1060 r1064 1 1 2 <?php 2 3 // +-----------------------------------------------------------------------+ … … 153 154 // destruction of all the related elements 154 155 $query = ' 155 SELECT id 156 FROM '.IMAGES_TABLE.' 157 WHERE storage_category_id IN ( 158 '.wordwrap(implode(', ', $ids), 80, "\n").') 156 SELECT image_id 157 FROM '.IMAGE_CATEGORY_TABLE.' 158 WHERE is_storage = \'true\' 159 AND category_id IN ('. 160 wordwrap( 161 implode(', ', $ids), 162 80, 163 "\n" 164 ). 165 ') 159 166 ;'; 160 167 $result = pwg_query($query); … … 162 169 while ($row = mysql_fetch_array($result)) 163 170 { 164 array_push($element_ids, $row['i d']);171 array_push($element_ids, $row['image_id']); 165 172 } 166 173 delete_elements($element_ids); … … 181 188 ;'; 182 189 pwg_query($query); 190 183 191 $query = ' 184 192 DELETE FROM '.GROUP_ACCESS_TABLE.' … … 187 195 ;'; 188 196 pwg_query($query); 197 198 // source/destination links deletion 199 $query = ' 200 SELECT destination, source 201 FROM '.CATEGORIES_LINK_TABLE.' 202 WHERE source IN ('.implode(',', $ids).') 203 OR destination IN ('.implode(',', $ids).') 204 ;'; 205 $result = pwg_query($query); 206 207 $sources_of = array(); 208 209 while ($row = mysql_fetch_array($result)) 210 { 211 if (!isset($sources_of[ $row['destination'] ])) 212 { 213 $sources_of[ $row['destination'] ] = array(); 214 } 215 216 array_push( 217 $sources_of[ $row['destination'] ], 218 $row['source'] 219 ); 220 } 221 222 foreach ($sources_of as $destination => $sources) 223 { 224 delete_sources($destination, $sources); 225 } 226 227 update_category(); 189 228 190 229 // destruction of the category … … 396 435 COUNT(image_id) AS nb_images, 397 436 MAX(date_available) AS date_last 398 FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id 437 FROM '.IMAGES_TABLE.' 438 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id 399 439 WHERE category_id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").') 400 440 GROUP BY category_id … … 403 443 $datas = array(); 404 444 $query_ids = array(); 405 while ( $row = mysql_fetch_array( $result ))445 while ($row = mysql_fetch_array($result)) 406 446 { 407 447 array_push($query_ids, $row['category_id']); 408 array_push($datas, array('id' => $row['category_id'], 409 'date_last' => $row['date_last'], 410 'nb_images' => $row['nb_images'])); 448 449 array_push( 450 $datas, 451 array( 452 'id' => $row['category_id'], 453 'date_last' => $row['date_last'], 454 'nb_images' => $row['nb_images'] 455 ) 456 ); 411 457 } 412 458 // if all links between a category and elements have disappeared, no line … … 414 460 foreach (array_diff($cat_ids, $query_ids) as $id) 415 461 { 416 array_push($datas, array('id' => $id, 'nb_images' => 0)); 417 } 418 419 $fields = array('primary' => array('id'), 420 'update' => array('date_last', 'nb_images')); 421 mass_updates(CATEGORIES_TABLE, $fields, $datas); 462 array_push( 463 $datas, 464 array( 465 'id' => $id, 466 'nb_images' => 0, 467 ) 468 ); 469 } 470 471 mass_updates( 472 CATEGORIES_TABLE, 473 array( 474 'primary' => array('id'), 475 'update' => array('date_last', 'nb_images') 476 ), 477 $datas 478 ); 422 479 423 480 // representative pictures … … 1292 1349 function update_path() 1293 1350 { 1294 $query = ' 1295 SELECT DISTINCT(storage_category_id) 1296 FROM '.IMAGES_TABLE.' 1297 ;'; 1298 $cat_ids = array_from_query($query, 'storage_category_id'); 1299 $fulldirs = get_fulldirs($cat_ids); 1300 1301 foreach ($cat_ids as $cat_id) 1351 $images_of = array(); 1352 1353 $query = ' 1354 SELECT category_id, image_id 1355 FROM '.IMAGE_CATEGORY_TABLE.' 1356 WHERE is_storage = \'true\' 1357 ;'; 1358 $result = pwg_query($query); 1359 while ($row = mysql_fetch_array($result)) 1360 { 1361 if (!isset($images_of[ $row['category_id'] ])) 1362 { 1363 $images_of[ $row['category_id'] ] = array(); 1364 } 1365 1366 array_push( 1367 $images_of[ $row['category_id'] ], 1368 $row['image_id'] 1369 ); 1370 } 1371 1372 $fulldirs = get_fulldirs( 1373 array_keys($images_of) 1374 ); 1375 1376 foreach ($images_of as $cat_id => $image_ids) 1302 1377 { 1303 1378 $query = ' 1304 1379 UPDATE '.IMAGES_TABLE.' 1305 1380 SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file) 1306 WHERE storage_category_id = '.$cat_id.' 1381 WHERE id IN ('. 1382 wordwrap( 1383 implode(', ', $image_ids), 1384 80, 1385 "\n"). 1386 ') 1307 1387 ;'; 1308 1388 pwg_query($query); … … 1523 1603 ); 1524 1604 } 1605 1606 /** 1607 * Returns all destinations of a list of source categories. This function 1608 * solves transitivity. 1609 * 1610 * @param mixed array of category ids, empty for all categories 1611 */ 1612 function get_destinations($categories = 'all') 1613 { 1614 $query = ' 1615 SELECT source, destination 1616 FROM '.CATEGORIES_LINK_TABLE.' 1617 '; 1618 $result = pwg_query($query); 1619 1620 $destinations_of = array(); 1621 1622 while ($row = mysql_fetch_array($result)) 1623 { 1624 if (!isset($destinations_of[ $row['source'] ])) 1625 { 1626 $destinations_of[ $row['source'] ] = array(); 1627 } 1628 1629 array_push( 1630 $destinations_of[ $row['source'] ], 1631 $row['destination'] 1632 ); 1633 } 1634 1635 // transitivity resolution: if " => " means "source of", if A=>B=>C 1636 // implies A=>B and A=>C. So A has 2 destinations: B and C. 1637 do 1638 { 1639 // let's suppose we only need a single turn 1640 $need_new_turn = false; 1641 1642 foreach ($destinations_of as $source => $destinations) 1643 { 1644 foreach ($destinations as $destination) 1645 { 1646 // does the current destination has destinations itself? 1647 if (isset($destinations_of[$destination])) 1648 { 1649 // are there destinations of current destination not already among 1650 // destinations of the current source? (advise: take a piece of 1651 // paper and draw a schema). The source itself must not be counted 1652 // as a destination, thus avoiding cyclic links. 1653 $missing_destinations = array_diff( 1654 $destinations_of[$destination], 1655 $destinations, 1656 array($source) // no cyclic link 1657 ); 1658 1659 if (count($missing_destinations) > 0) 1660 { 1661 $destinations_of[$source] = array_unique( 1662 array_merge( 1663 $destinations, 1664 $missing_destinations 1665 ) 1666 ); 1667 1668 // a category has a least one new destination, we have to check 1669 // one more time that it doesn't generate more destinations 1670 $need_new_turn = true; 1671 } 1672 } 1673 } 1674 } 1675 } while ($need_new_turn); 1676 1677 if (is_array($categories)) 1678 { 1679 $filtered_destinations_of = array(); 1680 1681 // Even if there is no destinations for the requested categories, we 1682 // return empty arrays 1683 foreach ($categories as $category) 1684 { 1685 $filtered_destinations_of[$category] = array(); 1686 } 1687 1688 foreach ($destinations_of as $source => $destinations) 1689 { 1690 if (in_array($source, $categories)) 1691 { 1692 $filtered_destinations_of[$source] = $destinations; 1693 } 1694 } 1695 1696 return $filtered_destinations_of; 1697 } 1698 else 1699 { 1700 return $destinations_of; 1701 } 1702 } 1703 1704 /** 1705 * Returns all sources of a list of destination categories. This function 1706 * solves transitivity. 1707 * 1708 * @param mixed array of category ids, empty for all categories 1709 */ 1710 function get_sources($categories = 'all') 1711 { 1712 $destinations_of = get_destinations(); 1713 1714 $sources_of = array(); 1715 1716 foreach ($destinations_of as $source => $destinations) 1717 { 1718 foreach ($destinations as $destination) 1719 { 1720 if (!isset($sources_of[$destination])) 1721 { 1722 $sources_of[$destination] = array(); 1723 } 1724 1725 array_push($sources_of[$destination], $source); 1726 } 1727 } 1728 1729 // eventually, filter 1730 if (is_array($categories)) 1731 { 1732 $filtered_sources_of = array(); 1733 1734 // Even if there is no sources for the requested categories, we return 1735 // empty arrays 1736 foreach ($categories as $category) 1737 { 1738 $filtered_sources_of[$category] = array(); 1739 } 1740 1741 foreach ($sources_of as $destination => $sources) 1742 { 1743 if (in_array($destination, $categories)) 1744 { 1745 $filtered_sources_of[$destination] = $sources; 1746 } 1747 } 1748 1749 return $filtered_sources_of; 1750 } 1751 else 1752 { 1753 return $sources_of; 1754 } 1755 } 1756 1757 /** 1758 * Checks categories links are respected for a given list of destinations. 1759 * 1760 * Checking categories links means that each destination must be associated 1761 * to the images of its sources. 1762 * 1763 * @param mixed source category ids 1764 */ 1765 function check_links($destinations = 'all') 1766 { 1767 $sources_of = get_sources($destinations); 1768 1769 if (empty($sources_of)) 1770 { 1771 return true; 1772 } 1773 1774 // we need to search images of all sources and destinations 1775 $images_of = array(); 1776 1777 foreach ($sources_of as $destination => $sources) 1778 { 1779 $images_of[$destination] = array(); 1780 1781 foreach ($sources as $source) 1782 { 1783 $images_of[$source] = array(); 1784 } 1785 } 1786 1787 $query = ' 1788 SELECT image_id, category_id 1789 FROM '.IMAGE_CATEGORY_TABLE.' 1790 WHERE category_id IN ('. 1791 implode(',', array_keys($images_of)). 1792 ') 1793 ;'; 1794 $result = pwg_query($query); 1795 1796 while ($row = mysql_fetch_array($result)) 1797 { 1798 array_push( 1799 $images_of[ $row['category_id'] ], 1800 $row['image_id'] 1801 ); 1802 } 1803 1804 $inserts = array(); 1805 1806 foreach ($sources_of as $destination => $sources) 1807 { 1808 // merge all images from the sources of this destination 1809 $sources_images = array(); 1810 1811 foreach ($sources as $source) 1812 { 1813 $sources_images = array_merge( 1814 $sources_images, 1815 $images_of[$source] 1816 ); 1817 } 1818 1819 $sources_images = array_unique($sources_images); 1820 1821 // are there images among the sources that are not linked to the 1822 // destination? 1823 $missing_images = array_diff( 1824 $sources_images, 1825 $images_of[$destination] 1826 ); 1827 1828 // if we find missing images (missing links in reality), we prepare the 1829 // final mass_inserts 1830 if (count($missing_images) > 0) 1831 { 1832 foreach ($missing_images as $missing_image) 1833 { 1834 array_push( 1835 $inserts, 1836 array( 1837 'category_id' => $destination, 1838 'image_id' => $missing_image, 1839 ) 1840 ); 1841 } 1842 } 1843 } 1844 1845 if (count($inserts) > 0) 1846 { 1847 mass_inserts( 1848 IMAGE_CATEGORY_TABLE, 1849 array_keys($inserts[0]), 1850 $inserts 1851 ); 1852 } 1853 } 1854 1855 /** 1856 * Based on categories links, delete image_category links on destinations. 1857 * 1858 * The rule is the following: if an image belong to the category and to the 1859 * source, we suppose it comes from the source. If the source/destination 1860 * link is broken, we delete the image/category link if the only origin of 1861 * the link was the broken categories link. 1862 * 1863 * Example: "=>" means "source of". Between brackets the associated images. 1864 * 1865 * A (1,2,9) => \ 1866 * |=> C (1,2,3,4,5,9) => D (1,2,3,4,5,6,9) 1867 * B (3,4,9) => / 1868 * 1869 * In category C, we suppose (1,2) come from A, (3,4) from B, 9 from A or B 1870 * and 5 was manually added. In category D, 6 was added manually. 1871 * 1872 * If we break A=>C, C and D loose (1,2) but not 9 because it can come from 1873 * B. If we break C=>D, D loose (3,4,5,9) but not 6 because it was 1874 * associated manually to 9. 1875 * 1876 * Warning: only virtual links can be removed, physical links are protected. 1877 * 1878 * @param int destination 1879 * @param array sources 1880 */ 1881 function delete_sources($destination, $sources) 1882 { 1883 // if no sources to unlink, we stop with OK status 1884 if (count($sources) == 0) 1885 { 1886 return true; 1887 } 1888 1889 $query = ' 1890 DELETE 1891 FROM '.CATEGORIES_LINK_TABLE.' 1892 WHERE destination = '.$destination.' 1893 AND source IN ('.implode(',', $sources).') 1894 ;'; 1895 pwg_query($query); 1896 1897 // The strategy is the following: 1898 // 1899 // * first we brutally delete the image/category associations on 1900 // destinations categories for all images belonging to sources. 1901 // 1902 // * then we check_links on destinations to rebuild missing image/category 1903 // associations. 1904 1905 // what are the images associated to the sources to unlink 1906 $query = ' 1907 SELECT image_id 1908 FROM '.IMAGE_CATEGORY_TABLE.' 1909 WHERE category_id IN ('. 1910 implode(',', $sources). 1911 ') 1912 ;'; 1913 $sources_images = array_unique( 1914 array_from_query($query, 'image_id') 1915 ); 1916 1917 if (count($sources_images) == 0) 1918 { 1919 return true; 1920 } 1921 1922 // retrieve all direct and indirect destinations of the current 1923 // destination 1924 $destinations_of = get_destinations(array($destination)); 1925 1926 $destinations = array_merge( 1927 array($destination), 1928 $destinations_of[$destination] 1929 ); 1930 1931 // unlink sources images from destinations 1932 $query = ' 1933 DELETE 1934 FROM '.IMAGE_CATEGORY_TABLE.' 1935 WHERE category_id IN ('.implode(',', $destinations).') 1936 AND image_id IN ('.implode(',', $sources_images).') 1937 AND is_storage = \'false\' 1938 ;'; 1939 pwg_query($query); 1940 1941 // if the representative thumbnail of destinations was a picture from 1942 // $sources_images, we request a new random representant 1943 $query = ' 1944 SELECT id, representative_picture_id 1945 FROM '.CATEGORIES_TABLE.' 1946 WHERE id IN ('.implode(',', $destinations).') 1947 ;'; 1948 $result = pwg_query($query); 1949 1950 $request_random = array(); 1951 1952 while ($row = mysql_fetch_array($result)) 1953 { 1954 if (isset($row['representative_picture_id'])) 1955 { 1956 if (in_array($row['representative_picture_id'], $sources_images)) 1957 { 1958 array_push($request_random, $row['id']); 1959 } 1960 } 1961 } 1962 1963 set_random_representant($request_random); 1964 1965 // eventually, we check_links to rebuild missing associations 1966 check_links($destinations); 1967 1968 return true; 1969 } 1970 1971 /** 1972 * create a virtual category 1973 * 1974 * @param string category name 1975 * @param int parent category id 1976 * @return array with ('info' and 'id') or ('error') key 1977 */ 1978 function create_virtual_category($category_name, $parent_id=null) 1979 { 1980 global $conf; 1981 1982 // is the given category name only containing blank spaces ? 1983 if (preg_match('/^\s*$/', $category_name)) 1984 { 1985 return array('error' => l10n('cat_error_name')); 1986 } 1987 1988 $parent_id = !empty($parent_id) ? $parent_id : 'NULL'; 1989 1990 $query = ' 1991 SELECT MAX(rank) 1992 FROM '.CATEGORIES_TABLE.' 1993 WHERE id_uppercat '.(is_numeric($parent_id) ? '= '.$parent_id : 'IS NULL').' 1994 ;'; 1995 list($current_rank) = mysql_fetch_array(pwg_query($query)); 1996 1997 $insert = array( 1998 'name' => $category_name, 1999 'rank' => ++$current_rank, 2000 'commentable' => $conf['newcat_default_commentable'], 2001 'uploadable' => 'false', 2002 ); 2003 2004 if ($parent_id != 'NULL') 2005 { 2006 $query = ' 2007 SELECT id, uppercats, global_rank, visible, status 2008 FROM '.CATEGORIES_TABLE.' 2009 WHERE id = '.$parent_id.' 2010 ;'; 2011 $parent = mysql_fetch_array(pwg_query($query)); 2012 2013 $insert{'id_uppercat'} = $parent{'id'}; 2014 $insert{'global_rank'} = $parent{'global_rank'}.'.'.$insert{'rank'}; 2015 2016 // at creation, must a category be visible or not ? Warning : if the 2017 // parent category is invisible, the category is automatically create 2018 // invisible. (invisible = locked) 2019 if ('false' == $parent['visible']) 2020 { 2021 $insert{'visible'} = 'false'; 2022 } 2023 else 2024 { 2025 $insert{'visible'} = $conf['newcat_default_visible']; 2026 } 2027 2028 // at creation, must a category be public or private ? Warning : if the 2029 // parent category is private, the category is automatically create 2030 // private. 2031 if ('private' == $parent['status']) 2032 { 2033 $insert{'status'} = 'private'; 2034 } 2035 else 2036 { 2037 $insert{'status'} = $conf['newcat_default_status']; 2038 } 2039 } 2040 else 2041 { 2042 $insert{'visible'} = $conf['newcat_default_visible']; 2043 $insert{'status'} = $conf['newcat_default_status']; 2044 $insert{'global_rank'} = $insert{'rank'}; 2045 } 2046 2047 // we have then to add the virtual category 2048 mass_inserts( 2049 CATEGORIES_TABLE, 2050 array( 2051 'site_id', 'name', 'id_uppercat', 'rank', 'commentable', 2052 'uploadable', 'visible', 'status', 'global_rank', 2053 ), 2054 array($insert) 2055 ); 2056 2057 $inserted_id = mysql_insert_id(); 2058 2059 $query = ' 2060 UPDATE 2061 '.CATEGORIES_TABLE.' 2062 SET uppercats = \''. 2063 (isset($parent) ? $parent{'uppercats'}.',' : ''). 2064 $inserted_id. 2065 '\' 2066 WHERE id = '.$inserted_id.' 2067 ;'; 2068 pwg_query($query); 2069 2070 return array( 2071 'info' => l10n('cat_virtual_added'), 2072 'id' => $inserted_id, 2073 ); 2074 } 1525 2075 ?> -
trunk/admin/include/functions_metadata.php
r1029 r1064 225 225 SELECT id, path 226 226 FROM '.IMAGES_TABLE.' 227 WHERE storage_category_id IN ('.implode(',', $cat_ids).')'; 227 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id 228 WHERE is_storage = \'true\' 229 AND category_id IN ('.implode(',', $cat_ids).')'; 228 230 if ($only_new) 229 231 { -
trunk/admin/maintenance.php
r1004 r1064 42 42 case 'categories' : 43 43 { 44 check_links(); 44 45 update_uppercats(); 45 46 update_category('all'); -
trunk/admin/picture_modify.php
r1004 r1064 172 172 SELECT * 173 173 FROM '.IMAGES_TABLE.' 174 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id 174 175 WHERE id = '.$_GET['image_id'].' 176 AND is_storage = \'true\' 175 177 ;'; 176 178 $row = mysql_fetch_array(pwg_query($query)); 177 179 178 $storage_category_id = $row[' storage_category_id'];180 $storage_category_id = $row['category_id']; 179 181 180 182 // Navigation path … … 342 344 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id 343 345 WHERE image_id = '.$_GET['image_id'].' 344 AND i d != '.$storage_category_id.'346 AND is_storage = \'false\' 345 347 ;'; 346 348 display_select_cat_wrapper($query, array(), 'associated_option'); -
trunk/admin/rating.php
r1059 r1064 169 169 } 170 170 171 $query = 'SELECT i.id, i.path, i.file, i.tn_ext, i.average_rate, i.storage_category_id, 172 MAX(r.date) as recently_rated, COUNT(r.rate) as nb_rates, 173 SUM(r.rate) as sum_rates, ROUND(STD(r.rate),2) as std_rates 174 FROM '.RATE_TABLE.' AS r LEFT JOIN '.IMAGES_TABLE.' AS i 175 ON r.element_id=i.id 176 WHERE 1=1 ' . $display_filter . ' 177 GROUP BY r.element_id 178 ORDER BY ' . $available_order_by[$order_by_index][1] .' 179 LIMIT '.$start.','.$elements_per_page . 180 ';'; 171 $query = ' 172 SELECT i.id, 173 i.path, 174 i.file, 175 i.tn_ext, 176 i.average_rate, 177 MAX(r.date) AS recently_rated, 178 COUNT(r.rate) AS nb_rates, 179 SUM(r.rate) AS sum_rates, 180 ROUND(STD(r.rate),2) AS std_rates, 181 ic.category_id AS storage_category_id 182 FROM '.RATE_TABLE.' AS r 183 LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id 184 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id 185 WHERE 1 = 1 ' . $display_filter . ' 186 AND ic.is_storage = \'true\' 187 GROUP BY r.element_id 188 ORDER BY ' . $available_order_by[$order_by_index][1] .' 189 LIMIT '.$start.','.$elements_per_page.' 190 ;'; 181 191 182 192 $images = array(); … … 189 199 foreach ($images as $image) 190 200 { 191 $thumbnail_src = get_thumbnail_src( 192 $image['path'], $image['tn_ext'] 193 );194 195 $image_url = PHPWG_ROOT_PATH.'picture.php?'.196 'cat=' . $image['storage_category_id'].197 '&image_id=' . $image['id'];201 $thumbnail_src = get_thumbnail_src($image['path'], $image['tn_ext']); 202 203 $image_url = 204 PHPWG_ROOT_PATH.'picture.php?'. 205 'cat=' . $image['storage_category_id']. 206 '&image_id=' . $image['id'] 207 ; 198 208 199 209 $query = 'SELECT * -
trunk/admin/site_reader_local.php
r1058 r1064 45 45 { 46 46 global $errors; 47 47 48 if (!is_dir($this->site_url)) 48 49 { 49 array_push($errors, array('path' => $this->site_url, 'type' => 'PWG-ERROR-NO-FS')); 50 array_push( 51 $errors, 52 array( 53 'path' => $this->site_url, 54 'type' => 'PWG-ERROR-NO-FS' 55 ) 56 ); 57 50 58 return false; 51 59 } 60 52 61 return true; 53 62 } … … 136 145 { 137 146 global $conf; 138 $update_fields = array( 'has_high', 'representative_ext', 139 'filesize', 'width', 'height' ); 147 148 $update_fields = array( 149 'has_high', 'representative_ext', 'filesize', 'width', 'height' 150 ); 151 140 152 if ($conf['use_exif']) 141 153 { … … 155 167 ); 156 168 } 169 157 170 return $update_fields; 158 171 } … … 170 183 171 184 $filename = basename($file); 172 $data['has_high'] = $this->get_has_high( dirname($file), $filename ); 173 $data['representative_ext'] = $this->get_representative_ext( dirname($file), 174 get_filename_wo_extension($filename) ); 185 186 $data['has_high'] = $this->get_has_high(dirname($file), $filename); 187 188 $data['representative_ext'] = $this->get_representative_ext( 189 dirname($file), 190 get_filename_wo_extension($filename) 191 ); 175 192 176 193 $data['filesize'] = floor(filesize($file)/1024); … … 205 222 } 206 223 } 224 207 225 return $data; 208 226 } … … 213 231 { 214 232 global $conf; 215 $base_test = $path.'/pwg_representative/'; 216 $base_test.= $filename_wo_ext.'.'; 233 $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.'; 217 234 foreach ($conf['picture_ext'] as $ext) 218 235 { … … 229 246 { 230 247 global $conf; 231 $base_test = $path.'/thumbnail/'; 232 $base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.'; 248 249 $base_test = 250 $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.'; 251 233 252 foreach ($conf['picture_ext'] as $ext) 234 253 { … … 239 258 } 240 259 } 260 241 261 return null; 242 262 } … … 248 268 return 'true'; 249 269 } 270 250 271 return null; 251 272 } -
trunk/admin/site_reader_remote.php
r1058 r1064 40 40 { 41 41 $this->site_url = $url; 42 $this->insert_attributes = array('tn_ext', 'representative_ext', 'has_high'); 43 $this->update_attributes = array( 'representative_ext', 'has_high', 'filesize', 'width', 'height' ); 42 $this->insert_attributes = array( 43 'tn_ext', 'representative_ext', 'has_high' 44 ); 45 $this->update_attributes = array( 46 'representative_ext', 'has_high', 'filesize', 'width', 'height' 47 ); 44 48 } 45 49 … … 52 56 { 53 57 global $errors; 58 54 59 $listing_file = $this->site_url.'/listing.xml'; 55 60 if (@fopen($listing_file, 'r')) … … 59 64 $xml_content = getXmlCode($listing_file); 60 65 $info_xml_element = getChild($xml_content, 'informations'); 61 if ( getAttribute($info_xml_element , 'phpwg_version') != PHPWG_VERSION ) 62 { 63 array_push($errors, array('path' => $listing_file, 'type' => 'PWG-ERROR-VERSION')); 66 if (getAttribute($info_xml_element , 'phpwg_version') != PHPWG_VERSION) 67 { 68 array_push( 69 $errors, 70 array( 71 'path' => $listing_file, 72 'type' => 'PWG-ERROR-VERSION' 73 ) 74 ); 75 64 76 return false; 65 77 } 66 $meta_attributes = explode ( ',', 67 getAttribute($info_xml_element , 'metadata') ); 68 $this->update_attributes = array_merge( $this->update_attributes, $meta_attributes ); 78 79 $this->update_attributes = array_merge( 80 $this->update_attributes, 81 explode(',', getAttribute($info_xml_element, 'metadata')) 82 ); 83 69 84 $this->build_structure($xml_content, '', 0); 85 70 86 return true; 71 87 } 72 88 else 73 89 { 74 array_push($errors, array('path' => $listing_file, 'type' => 'PWG-ERROR-NOLISTING')); 90 array_push( 91 $errors, 92 array( 93 'path' => $listing_file, 94 'type' => 'PWG-ERROR-NOLISTING' 95 ) 96 ); 97 75 98 return false; 76 99 } … … 84 107 { 85 108 $full_dir = $this->site_url . $dir; 86 if ( $full_dir!=$basedir87 and strpos($full_dir, $basedir)===0109 if ($full_dir != $basedir 110 and strpos($full_dir, $basedir) === 0 88 111 ) 89 112 { … … 106 129 { 107 130 $full_dir = $this->site_url . $dir; 108 if ( strpos($full_dir, $path)===0)109 { 110 foreach ( 131 if (strpos($full_dir, $path) === 0) 132 { 133 foreach ($files as $file) 111 134 { 112 $data = $this->get_element_attributes($file, 113 $this->insert_attributes); 135 $data = $this->get_element_attributes( 136 $file, 137 $this->insert_attributes 138 ); 114 139 $elements[$file] = $data; 115 140 } … … 130 155 function get_element_update_attributes($file) 131 156 { 132 return $this->get_element_attributes($file, 133 $this->update_attributes); 157 return $this->get_element_attributes( 158 $file, 159 $this->update_attributes 160 ); 134 161 } 135 162 … … 144 171 { 145 172 $xml_element = $this->site_files[$file]; 146 if ( ! isset($xml_element))173 if (!isset($xml_element)) 147 174 { 148 175 return null; … … 178 205 if ($basedir != '') 179 206 { 180 $xml_elements = getChildren( getChild($xml_content, 'root'), 'element' ); 207 $xml_elements = getChildren( 208 getChild($xml_content, 'root'), 209 'element' 210 ); 181 211 foreach ($xml_elements as $xml_element) 182 212 { 183 213 $path = getAttribute($xml_element, 'path'); 184 214 $this->site_files[$path] = $xml_element; 185 array_push( 215 array_push($this->site_dirs[$basedir], $path); 186 216 } 187 217 } -
trunk/admin/site_update.php
r1058 r1064 28 28 if (!defined('PHPWG_ROOT_PATH')) 29 29 { 30 die 30 die('Hacking attempt!'); 31 31 } 32 32 include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); 33 33 34 if (! is_numeric($_GET['site']))34 if (!is_numeric($_GET['site'])) 35 35 { 36 36 die ('site param missing or invalid'); 37 37 } 38 38 $site_id = $_GET['site']; 39 $query='SELECT galleries_url FROM '.SITES_TABLE.' 40 WHERE id='.$site_id.' 41 ;'; 42 list($site_url)=mysql_fetch_row(pwg_query($query)); 43 if (! isset($site_url) ) 44 { 45 die ("site $site_id does not exist"); 39 40 $query=' 41 SELECT galleries_url 42 FROM '.SITES_TABLE.' 43 WHERE id = '.$site_id.' 44 ;'; 45 list($site_url) = mysql_fetch_row(pwg_query($query)); 46 if (!isset($site_url)) 47 { 48 die('site '.$site_id.' does not exist'); 46 49 } 47 50 $site_is_remote = url_is_remote($site_url); … … 51 54 52 55 $error_labels = array( 53 'PWG-UPDATE-1' => array( l10n('update_wrong_dirname_short'), 54 l10n('update_wrong_dirname_info') ), 55 'PWG-UPDATE-2' => array( l10n('update_missing_tn_short'), 56 l10n('update_missing_tn_info') 57 . implode(',', $conf['picture_ext']) ), 58 'PWG-ERROR-NO-FS' => array( l10n('update_missing_file_or_dir'), 59 l10n('update_missing_file_or_dir_info')), 60 'PWG-ERROR-VERSION' => array( l10n('update_err_pwg_version_differs'), 61 l10n('update_err_pwg_version_differs_info')), 62 'PWG-ERROR-NOLISTING' => array( l10n('update_err_remote_listing_not_found'), 63 l10n('update_err_remote_listing_not_found_info')) 64 ); 56 'PWG-UPDATE-1' => array( 57 l10n('update_wrong_dirname_short'), 58 l10n('update_wrong_dirname_info') 59 ), 60 'PWG-UPDATE-2' => array( 61 l10n('update_missing_tn_short'), 62 l10n('update_missing_tn_info').implode(',', $conf['picture_ext']) 63 ), 64 'PWG-ERROR-NO-FS' => array( 65 l10n('update_missing_file_or_dir'), 66 l10n('update_missing_file_or_dir_info') 67 ), 68 'PWG-ERROR-VERSION' => array( 69 l10n('update_err_pwg_version_differs'), 70 l10n('update_err_pwg_version_differs_info') 71 ), 72 'PWG-ERROR-NOLISTING' => array( 73 l10n('update_err_remote_listing_not_found'), 74 l10n('update_err_remote_listing_not_found_info') 75 ) 76 ); 65 77 $errors = array(); 66 78 $infos = array(); … … 68 80 if ($site_is_remote) 69 81 { 70 include_once( 82 include_once(PHPWG_ROOT_PATH.'admin/site_reader_remote.php'); 71 83 $site_reader = new RemoteSiteReader($site_url); 72 84 } … … 77 89 } 78 90 79 $general_failure =true;91 $general_failure = true; 80 92 if (isset($_POST['submit'])) 81 93 { … … 214 226 if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir)) 215 227 { 216 $insert = array(); 217 218 $insert{'id'} = $next_id++; 219 $insert{'dir'} = $dir; 220 $insert{'name'} = str_replace('_', ' ', $dir); 221 $insert{'site_id'} = $site_id; 222 $insert{'commentable'} = $conf['newcat_default_commentable']; 223 if (! $site_is_remote) 224 { 225 $insert{'uploadable'} = $conf['newcat_default_uploadable']; 226 } 227 else 228 { 229 $insert{'uploadable'} = 'false'; 230 } 231 $insert{'status'} = $conf{'newcat_default_status'}; 232 $insert{'visible'} = $conf{'newcat_default_visible'}; 228 $insert = array( 229 'id' => $next_id++, 230 'dir' => $dir, 231 'name' => str_replace('_', ' ', $dir), 232 'site_id' => $site_id, 233 'commentable' => $conf['newcat_default_commentable'], 234 'uploadable' => $site_is_remote 235 ? false 236 : $conf['newcat_default_uploadable'], 237 'status' => $conf{'newcat_default_status'}, 238 'visible' => $conf{'newcat_default_visible'}, 239 ); 233 240 234 241 if (isset($db_fulldirs[dirname($fulldir)])) … … 259 266 260 267 array_push($inserts, $insert); 261 array_push($infos, array('path' => $fulldir, 262 'info' => l10n('update_research_added'))); 268 array_push( 269 $infos, 270 array( 271 'path' => $fulldir, 272 'info' => l10n('update_research_added') 273 ) 274 ); 263 275 264 276 // add the new category to $db_categories and $db_fulldirs array … … 276 288 else 277 289 { 278 array_push($errors, array('path' => $fulldir, 'type' => 'PWG-UPDATE-1')); 290 array_push( 291 $errors, 292 array( 293 'path' => $fulldir, 294 'type' => 'PWG-UPDATE-1' 295 ) 296 ); 279 297 } 280 298 } … … 339 357 SELECT id, path 340 358 FROM '.IMAGES_TABLE.' 341 WHERE storage_category_id IN ( 342 '.wordwrap(implode(', ', $cat_ids), 80, "\n").') 359 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id 360 WHERE is_storage = \'true\' 361 AND category_id IN ('. 362 wordwrap( 363 implode(', ', $cat_ids), 364 80, 365 "\n" 366 ). 367 ') 343 368 ;'; 344 369 $result = pwg_query($query); … … 362 387 array_push( 363 388 $db_unvalidated, 364 array_search($row['storage_category_id'], 365 $db_fulldirs).'/'.$row['file'] 389 array_search( 390 $row['storage_category_id'], 391 $db_fulldirs) 392 .'/'.$row['file'] 366 393 ); 367 394 } … … 392 419 if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename)) 393 420 { 394 array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-1')); 421 array_push( 422 $errors, 423 array( 424 'path' => $path, 425 'type' => 'PWG-UPDATE-1' 426 ) 427 ); 428 395 429 continue; 396 430 } … … 402 436 { 403 437 // if we found a thumnbnail corresponding to our picture... 404 if ( isset($fs[$path]['tn_ext']))438 if (isset($fs[$path]['tn_ext'])) 405 439 { 406 $insert{'id'} = $next_element_id++; 407 $insert{'file'} = $filename; 408 $insert{'storage_category_id'} = $db_fulldirs[$dirname]; 409 $insert{'date_available'} = CURRENT_DATE; 410 $insert{'tn_ext'} = $fs[$path]['tn_ext']; 411 if ( isset($fs[$path]['has_high']) ) 412 { 413 $insert{'has_high'} = $fs[$path]['has_high']; 414 } 415 else 416 { 417 $insert{'has_high'} = null; 418 } 419 $insert{'path'} = $path; 420 421 array_push($inserts, $insert); 422 array_push($insert_links, 423 array('image_id' => $insert{'id'}, 424 'category_id' => $insert{'storage_category_id'})); 425 array_push($infos, array('path' => $insert{'path'}, 426 'info' => l10n('update_research_added'))); 440 $insert = array( 441 'id' => $next_element_id++, 442 'file' => $filename, 443 'date_available' => CURRENT_DATE, 444 'tn_ext' => $fs[$path]['tn_ext'], 445 'has_high' => isset($fs[$path]['has_high']) 446 ? $fs[$path]['has_high'] 447 : null, 448 'path' => $path, 449 ); 450 451 array_push( 452 $inserts, 453 $insert 454 ); 455 456 array_push( 457 $insert_links, 458 array( 459 'image_id' => $insert{'id'}, 460 'category_id' => $db_fulldirs[$dirname], 461 'is_storage' => 'true', 462 ) 463 ); 464 array_push( 465 $infos, 466 array( 467 'path' => $insert{'path'}, 468 'info' => l10n('update_research_added') 469 ) 470 ); 427 471 } 428 472 else 429 473 { 430 array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-2')); 474 array_push( 475 $errors, 476 array( 477 'path' => $path, 478 'type' => 'PWG-UPDATE-2' 479 ) 480 ); 431 481 } 432 482 } 433 483 else 434 484 { 435 $insert{'id'} = $next_element_id++; 436 $insert{'file'} = $filename; 437 $insert{'storage_category_id'} = $db_fulldirs[$dirname]; 438 $insert{'date_available'} = CURRENT_DATE; 439 $insert{'has_high'} = $fs[$path]['has_high']; 440 if ( isset($fs[$path]['has_high']) ) 441 { 442 $insert{'has_high'} = $fs[$path]['has_high']; 443 } 444 else 445 { 446 $insert{'has_high'} = null; 447 } 448 $insert{'path'} = $path; 449 450 if ( isset($fs[$path]['tn_ext']) ) 451 { 452 $insert{'tn_ext'} = $fs[$path]['tn_ext']; 453 } 454 if (isset($fs[$path]['representative_ext'])) 455 { 456 $insert{'representative_ext'} = $fs[$path]['representative_ext']; 457 } 458 459 array_push($inserts, $insert); 460 array_push($insert_links, 461 array('image_id' => $insert{'id'}, 462 'category_id' => $insert{'storage_category_id'})); 463 array_push($infos, array('path' => $insert{'path'}, 464 'info' => l10n('update_research_added'))); 485 $insert = array( 486 'id' => $next_element_id++, 487 'file' => $filename, 488 'date_available' => CURRENT_DATE, 489 'path' => $path, 490 'has_high' => isset($fs[$path]['has_high']) 491 ? $fs[$path]['has_high'] 492 : null, 493 'tn_ext' => isset($fs[$path]['tn_ext']) 494 ? $fs[$path]['tn_ext'] 495 : null, 496 'representative_ext' => isset($fs[$path]['representative_ext']) 497 ? $fs[$path]['representative_ext'] 498 : null, 499 ); 500 501 array_push( 502 $inserts, 503 $insert 504 ); 505 506 array_push( 507 $insert_links, 508 array( 509 'image_id' => $insert{'id'}, 510 'category_id' => $db_fulldirs[$dirname], 511 'is_storage' => 'true', 512 ) 513 ); 514 515 array_push( 516 $infos, 517 array( 518 'path' => $insert{'path'}, 519 'info' => l10n('update_research_added') 520 ) 521 ); 465 522 } 466 523 } … … 471 528 { 472 529 // inserts all new elements 473 $dbfields = array( 474 'id','file','storage_category_id','date_available','tn_ext' 475 ,'representative_ext', 'has_high', 'path' 476 ); 477 mass_inserts(IMAGES_TABLE, $dbfields, $inserts); 478 479 // insert all links between new elements and their storage category 480 $dbfields = array('image_id','category_id'); 481 mass_inserts(IMAGE_CATEGORY_TABLE, $dbfields, $insert_links); 530 mass_inserts( 531 IMAGES_TABLE, 532 array( 533 'id', 'file', 'date_available', 'tn_ext', 'representative_ext', 534 'has_high', 'path', 535 ), 536 $inserts 537 ); 538 539 // inserts all links between new elements and their storage category 540 mass_inserts( 541 IMAGE_CATEGORY_TABLE, 542 array( 543 'image_id','category_id', 'is_storage', 544 ), 545 $insert_links 546 ); 482 547 } 483 548 $counts['new_elements'] = count($inserts); … … 533 598 SELECT id 534 599 FROM '.IMAGES_TABLE.' 535 WHERE storage_category_id = \''.$row['storage_category_id'].'\' 600 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id 601 WHERE is_storage = \'true\' 602 AND category_id = '.$row['storage_category_id'].' 536 603 AND file = \''.$row['file'].'\' 537 604 ;'; … … 580 647 if (!$simulate) 581 648 { 649 $start = get_moment(); 650 check_links('all'); 651 echo '<!-- check_links(all) : '; 652 echo get_elapsed_time($start,get_moment()); 653 echo ' -->'."\n"; 582 654 $start = get_moment(); 583 655 update_category('all'); -
trunk/include/constants.php
r1028 r1064 63 63 define('SEARCH_TABLE', $prefixeTable.'search'); 64 64 define('USER_MAIL_NOTIFICATION_TABLE', $prefixeTable.'user_mail_notification'); 65 65 define('CATEGORIES_LINK_TABLE', $prefixeTable.'categories_link'); 66 66 ?> -
trunk/install/phpwebgallery_structure.sql
r1041 r1064 1 -- MySQL dump 10.92 -- 3 -- Host: localhost Database: pwg _dev_bsf1 -- MySQL dump 9.11 2 -- 3 -- Host: localhost Database: pwg-bsf 4 4 -- ------------------------------------------------------ 5 -- Server version 4. 1.15-nt5 -- Server version 4.0.24_Debian-10-log 6 6 7 7 -- … … 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 -- 45 56 -- Table structure for table `phpwebgallery_comments` 46 57 -- … … 128 139 `image_id` mediumint(8) unsigned NOT NULL default '0', 129 140 `category_id` smallint(5) unsigned NOT NULL default '0', 141 `is_storage` enum('true','false') default 'false', 130 142 PRIMARY KEY (`image_id`,`category_id`), 131 143 KEY `image_category_i1` (`image_id`), … … 296 308 297 309 -- 310 -- Table structure for table `phpwebgallery_user_mail_notification` 311 -- 312 313 DROP TABLE IF EXISTS `phpwebgallery_user_mail_notification`; 314 CREATE TABLE `phpwebgallery_user_mail_notification` ( 315 `user_id` smallint(5) NOT NULL default '0', 316 `check_key` varchar(128) binary NOT NULL default '', 317 `enabled` enum('true','false') NOT NULL default 'false', 318 `last_send` datetime default NULL, 319 PRIMARY KEY (`user_id`), 320 UNIQUE KEY `uidx_check_key` (`check_key`) 321 ) TYPE=MyISAM; 322 323 -- 298 324 -- Table structure for table `phpwebgallery_users` 299 325 -- … … 327 353 ) TYPE=MyISAM; 328 354 329 --330 -- Table structure for table `phpwebgallery_user_mail_notification`331 --332 333 DROP TABLE IF EXISTS `phpwebgallery_user_mail_notification`;334 CREATE TABLE `phpwebgallery_user_mail_notification`335 (336 `user_id` smallint(5) NOT NULL default '0',337 `check_key` varchar(128) binary NOT NULL,338 `enabled` enum('true','false') NOT NULL default 'false',339 `last_send` datetime default NULL,340 PRIMARY KEY (`user_id`),341 UNIQUE KEY `uidx_check_key` (`check_key`)342 ) TYPE=MyISAM; -
trunk/template/yoga/admin/cat_list.tpl
r1045 r1064 46 46 <p> 47 47 {L_ADD_VIRTUAL} : <input type="text" name="virtual_name" /> 48 <input type="hidden" name="rank" value="{NEXT_RANK}"/>49 48 <input type="submit" value="{L_SUBMIT}" name="submitAdd" /> 50 49 </p> -
trunk/template/yoga/admin/cat_modify.tpl
r1045 r1064 137 137 138 138 </form> 139 140 <form action="{F_ACTION}" method="POST" id="links"> 141 142 <fieldset> 143 <legend>{lang:Create a destination category}</legend> 144 145 <table> 146 <tr> 147 <td>{lang:virtual category name}</td> 148 <td><input type="text" name="virtual_name"></td> 149 </tr> 150 151 <tr> 152 <td>{lang:parent category}</td> 153 <td> 154 <select class="categoryList" name="parent"> 155 <!-- BEGIN category_option_parent --> 156 <option {category_option_parent.SELECTED} value="{category_option_parent.VALUE}">{category_option_parent.OPTION}</option> 157 <!-- END category_option_parent --> 158 </select> 159 </td> 160 </tr> 161 </table> 162 163 <p style="text-align:center;"> 164 <input type="submit" value="{lang:Submit}" name="submitAdd" /> 165 <input type="reset" value="{lang:Reset}" name="reset" /> 166 </p> 167 168 </fieldset> 169 170 <fieldset> 171 <legend>{lang:Source/destination links}</legend> 172 173 <table class="doubleSelect"> 174 <tr> 175 <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 --> 181 </select> 182 <p><input type="submit" value="»" name="destination_falsify" style="font-size:15px;"/></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;" /></p> 193 </td> 194 </tr> 195 </table> 196 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;"/></p> 207 </td> 208 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;" /></p> 217 </td> 218 </tr> 219 </table> 220 221 </fieldset> 222 </form>
Note: See TracChangeset
for help on using the changeset viewer.