source: extensions/SmartAlbums/include/init_cat_list.php @ 12523

Last change on this file since 12523 was 11546, checked in by mistic100, 13 years ago

keep category representant if possible

File size: 3.2 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3/**
4 * Add a link into categories list to regenerate associations
5 */
6$smart_count = 0;
7
8function smart_cat_list()
9{
10  global $template, $page, $smart_count;
11
12  $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&amp;parent_id='.$_GET['parent_id'] : null);
13 
14  /* get categories with smart filters */
15  $query = '
16SELECT DISTINCT id, name
17  FROM '.CATEGORIES_TABLE.' AS c
18    INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
19      ON c.id = cf.category_id';
20  if (!isset($_GET['parent_id']))
21  {
22    // $query.= '
23    // WHERE id_uppercat IS NULL';
24  }
25  else
26  {
27    $query .= '
28  WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\'';
29  }
30  $query .= '
31;';
32 
33  $smart_cats = hash_from_query($query, 'id'); 
34  $smart_count = count($smart_cats);
35 
36  if (isset($_GET['smart_generate']))
37  {
38    /* regenerate photo list | all (sub) categories */
39    if ($_GET['smart_generate'] == 'all')
40    {
41      foreach ($smart_cats as $category)
42      {
43        $associated_images = smart_make_associations($category['id']);
44        array_push(
45          $page['infos'], 
46          sprintf(
47            l10n('%d photos associated to album %s'), 
48            count($associated_images), 
49            '&laquo;'.trigger_event(
50              'render_category_name',
51              $category['name'],
52              'admin_cat_list'
53              ).'&raquo;'
54            )
55          );
56      }
57    }
58    /* regenerate photo list | one category */
59    else
60    {
61      $associated_images = smart_make_associations($_GET['smart_generate']);   
62      array_push(
63        $page['infos'], 
64        sprintf(
65          l10n('%d photos associated to album %s'), 
66          count($associated_images), 
67          '&laquo;'.trigger_event(
68            'render_category_name',
69            $smart_cats[$_GET['smart_generate']]['name'],
70            'admin_cat_list'
71            ).'&raquo;'
72          )
73        );
74    }
75   
76    define('SMART_NOT_UPDATE', 1);
77    invalidate_user_cache();
78  }
79 
80  // create regenerate link
81  $tpl_cat = array();
82  foreach ($smart_cats as $cat => $name)
83  {
84    $tpl_cat[$cat] = $self_url.'&amp;smart_generate='.$cat;
85  }
86  $tpl_cat['all'] = $self_url.'&amp;smart_generate=all';
87 
88  $template->assign(array(
89    'SMART_URL' => $tpl_cat,
90    'SMART_PATH' => SMART_PATH,
91  ));
92 
93  $template->set_prefilter('categories', 'smart_cat_list_prefilter');
94}
95
96
97function smart_cat_list_prefilter($content, &$smarty)
98{
99  global $smart_count;
100 
101  $search[0] = '{if isset($category.U_SYNC) }';
102  $replacement[0] = '
103{if isset($SMART_URL[$category.ID])}
104        <li><a href="{$SMART_URL[$category.ID]}" title="{\'Regenerate photos list of this SmartAlbum\'|@translate}"><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/synchronize.png" class="button" alt="{\'Regenerate photos list of this SmartAlbum\'|@translate}"></a></li>
105{/if}'
106.$search[0];
107
108  if ($smart_count > 0)
109  {
110    $search[1] = '</ul>
111</form>';
112    $replacement[1] = $search[1].'
113<form method="post" action="{$SMART_URL.all}">
114  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
115  <p><input class="submit" type="submit" value="{\'Regenerate photos list of all SmartAlbums\'|@translate}"></p>
116</form>';
117  }
118
119  return str_replace($search, $replacement, $content);
120}
121
122?>
Note: See TracBrowser for help on using the repository browser.