source: extensions/SmartAlbums/init_cat_modify.php @ 10884

Last change on this file since 10884 was 10871, checked in by mistic100, 13 years ago

repository for SmartAlbums

File size: 4.2 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4function smart_cat_modify()
5{
6  global $template;
7  include_once(SMART_PATH.'include/functions.inc.php');
8  $cat_id = $_GET['cat_id'];
9 
10  if (isset($_POST['submitFilters']))
11  {
12    // test if it was a Smart Album
13    $result = pwg_query("SELECT DISTINCT category_id FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");
14    $_was_smart = pwg_db_num_rows($result);
15   
16    /* this album is no longer a SmartAlbum */
17    if ($_was_smart AND !isset($_POST['is_smart']))
18    {
19      pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;");
20      pwg_query("DELETE FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");
21    }
22    /* no filter selected */
23    else if (isset($_POST['is_smart']) AND !isset($_POST['filters']))
24    {
25      array_push($page['errors'], l10n('No filter selected'));
26    }
27    /* everything is fine */
28    else if (isset($_POST['is_smart']) AND count($_POST['filters']) > 0)
29    {
30      pwg_query("DELETE FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");
31
32      foreach ($_POST['filters'] as $filter)
33      {
34        $error = false;
35        if ($filter['type'] == 'tags')
36        {
37          $filter['value'] = str_replace(' ', null, $filter['value']);
38        }
39        else if ($filter['type'] == 'date')
40        {
41          if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value']))
42          {
43            $error = true;
44            array_push($page['errors'], l10n('Date string is malformed'));
45          }
46        }
47        else if ($filter['type'] == 'limit')
48        {
49          if (!preg_match('#([0-9]{1,})#', $filter['value']))
50          {
51            $error = true;
52            array_push($page['errors'], l10n('Limit must be an integer'));
53          }
54          else if (isset($limit_is_set))
55          {
56            $error = true;
57            array_push($page['errors'], l10n('You can\'t use more than one limit'));
58          }
59          else
60          {
61            $limit_is_set = true;
62          }
63        }
64       
65        if ($error == false)
66        {
67          pwg_query("INSERT INTO ".CATEGORY_FILTERS_TABLE."
68            VALUES(".$cat_id.", '".$filter['type']."', '".$filter['cond']."', '".$filter['value']."');");
69        }
70      }
71     
72      $associated_images = SmartAlbums_make_associations($cat_id);
73      $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
74     
75      set_random_representant(array($cat_id));
76      invalidate_user_cache(true);
77    }
78  }
79     
80  /* select options */
81  $template->assign('options', array(
82    'tags' => array(
83      'all' => l10n('All these tags'),
84      'one' => l10n('One of these tags'),
85      'none' => l10n('None of these tags'),
86      'only' => l10n('Only these tags'),
87      ),
88    'date' => array(
89      'the' => l10n('Added the'),
90      'before' => l10n('Added before the'),
91      'after' => l10n('Added after the'),
92      ),
93    'limit' => array('limit' => 'limit'),
94  ));
95 
96  /* get filters for this album */
97  $filters = pwg_query("SELECT * FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id." ORDER BY type ASC, cond ASC;");
98  while ($filter = pwg_db_fetch_assoc($filters))
99  {
100    $template->append('filters', array(
101      'TYPE' => $filter['type'],
102      'COND' => $filter['cond'],
103      'VALUE' => $filter['value'],
104    ));
105  }
106 
107  /* get image number */
108  if ($template->get_template_vars('IMAGE_COUNT') == null)
109  {
110    list($image_num) = pwg_db_fetch_row(pwg_query("SELECT count(*) FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;"));
111    $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num));
112  }
113 
114  $template->assign(array(
115    'SMART_PATH' => SMART_PATH,
116    'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php',
117  )); 
118  $template->set_prefilter('categories', 'smart_cat_modify_prefilter');
119}
120
121
122function smart_cat_modify_prefilter($content, &$smarty)
123{
124  $search = '<form action="{$F_ACTION}" method="POST" id="links">';
125  $replacement = file_get_contents(SMART_PATH.'template/cat_modify.tpl')."\n".$search;
126  return str_replace($search, $replacement, $content);
127}
128
129?>
Note: See TracBrowser for help on using the repository browser.