source: extensions/delete_rate/admin/admin.php

Last change on this file was 8017, checked in by ddtddt, 13 years ago

[extension] - delete_rate - update

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3global $template, $conf, $user;
4include_once(PHPWG_ROOT_PATH .'admin/include/tabsheet.class.php');
5load_language('plugin.lang', RATE_PATH);
6$my_base_url = get_admin_plugin_menu_link(__FILE__);
7
8// +-----------------------------------------------------------------------+
9// | Check Access and exit when user status is not ok                      |
10// +-----------------------------------------------------------------------+
11check_status(ACCESS_ADMINISTRATOR);
12
13//-------------------------------------------------------- sections definitions
14
15
16
17// Gestion des onglets
18if (!isset($_GET['tab']))
19    $page['tab'] = 'rateall';
20else
21    $page['tab'] = $_GET['tab'];
22
23$tabsheet = new tabsheet();
24$tabsheet->add('rateall',
25               l10n('rate_onglet_all'),
26               $my_base_url.'&amp;tab=rateall');
27$tabsheet->add('ratephoto',
28               l10n('rate_onglet_photo'),
29               $my_base_url.'&amp;tab=ratephoto');
30$tabsheet->add('ratealbum',
31               l10n('rate_onglet_album'),
32               $my_base_url.'&amp;tab=ratealbum');
33                           
34$tabsheet->select($page['tab']);
35$tabsheet->assign();
36
37// Onglet gestion par photo
38switch ($page['tab'])
39{
40 case 'rateall':
41
42  $template->assign(
43    'gestion',
44    array(
45
46      ));
47
48//purge photo
49if (isset($_POST['submitchoixall']) and !is_adviser())
50        {
51        $query = '
52UPDATE ' . IMAGES_TABLE . '
53  SET average_rate= \'NULL\'
54    ;';
55$result = pwg_query($query);
56
57        $query = '
58TRUNCATE ' . RATE_TABLE . '
59    ;';
60$result = pwg_query($query);
61
62        array_push( $page['infos'], l10n('rate_totalok') );
63        }
64         
65    break;
66       
67  case 'ratephoto':
68
69//charge la liste des photos
70$groups = array();
71$query = '
72SELECT id,name
73  FROM ' . IMAGES_TABLE . '
74  ORDER BY id ASC;';
75$result = pwg_query($query);
76
77while ($row = mysql_fetch_array($result))
78        {
79  $groups[$row['id']] = $row['id'].' : '.$row['name'];
80        }
81       
82        $selected = 0;
83        $options[] = l10n('rate_select_photo');
84        $options['a'] = '----------------------';
85       
86foreach($groups as $listid => $listid2)
87        {
88    $options[$listid] = $listid2;
89        }
90  $template->assign(
91    'gestionA',
92    array(
93          'OPTIONS' => $options,
94      'SELECTED' => $selected
95      ));
96
97//purge photo
98if (isset($_POST['submitchoixphoto']) and is_numeric($_POST['delratephoto'])and (!$_POST['delratephoto'])==0 and !is_adviser())
99        {
100        $lire=$_POST['delratephoto'];
101        $query = '
102UPDATE ' . IMAGES_TABLE . '
103  SET average_rate = \'NULL\'
104  WHERE id = \''.$lire.'\'
105    ;';
106$result = pwg_query($query);
107
108        $query = '
109  DELETE FROM ' . RATE_TABLE . '
110  WHERE element_id = \''.$lire.'\'
111    ;';
112$result = pwg_query($query);
113       
114        array_push( $page['infos'], l10n('rate_photook') );
115        }
116         
117    break;
118       
119        case 'ratealbum':
120
121//charge la liste des catégories
122$groups = array();
123$query = '
124select id,name
125  FROM ' . CATEGORIES_TABLE . '
126  ORDER BY id ASC;';
127$result = pwg_query($query);
128
129while ($row = mysql_fetch_array($result))
130        {
131  $groups[$row['id']] = $row['id'].' : '.$row['name'];
132        }
133       
134        $selected = 0;
135        $options[] = l10n('rate_select_cat');
136        $options['a'] = '----------------------';
137       
138foreach($groups as $listid => $listid2)
139        {
140    $options[$listid] = $listid2;
141        }
142  $template->assign(
143    'gestionB',
144    array(
145          'OPTIONS' => $options,
146      'SELECTED' => $selected
147      ));
148       
149       
150
151//purge toutes les photos d'un album
152if (isset($_POST['submitchoixcat']) and is_numeric($_POST['delratecat'])and (!$_POST['delratecat'])==0 and !is_adviser())
153        {
154        $lire=$_POST['delratecat'];
155
156        $query = '
157select image_id
158  FROM ' . IMAGE_CATEGORY_TABLE . '
159  WHERE category_id = \''.$lire.'\'
160  ;';
161$result = pwg_query($query);
162
163$delval = array();
164while($row = mysql_fetch_array($result))
165        {
166    array_push($delval, $row['image_id']);
167        }
168
169foreach ($delval as $delrate)
170        {
171                $query = '
172                UPDATE ' . IMAGES_TABLE . '
173                SET average_rate = \'NULL\'
174                WHERE id = \''.$delrate.'\'
175    ;';
176$result = pwg_query($query);
177       
178                $query = '
179                DELETE FROM ' . RATE_TABLE . '
180                WHERE element_id = \''.$delrate.'\'
181                ;';
182                $result = pwg_query($query);
183        }
184        array_push( $page['infos'], l10n('rate_albumok') );       
185    break;
186        }
187} 
188
189$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); 
190$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
191?>
Note: See TracBrowser for help on using the repository browser.