source: extensions/ConcoursPhoto/admin/functions.inc.php @ 7690

Last change on this file since 7690 was 4368, checked in by tiico, 14 years ago

[ConcoursPhoto] Correct some bug, update database and add audit page (Need to be completed)

File size: 4.4 KB
Line 
1<?php
2
3// Get all generated csv files stored on RESULT directory
4function get_csvfile_result()
5{
6        $csvfile = array();
7    if (is_dir(CONCOURS_RESULT_FOLDER) )
8        {
9                $dir = opendir(CONCOURS_RESULT_FOLDER);
10                while ($file = readdir($dir)) 
11                {
12            // only csv file
13                        if ($file != '.' and $file != '..' and preg_match("/.csv/", $file)) 
14            {
15                                $path = CONCOURS_RESULT_FOLDER . $file;
16                                if (!is_dir($path) and !is_link($path)) 
17                                {
18                                        $concours_info = get_info_concours_from_csvfile($file);
19                                        $csvfile[$file] = array(
20                                                'name' => $file,
21                                                'link' => $path,
22                                                'conc_id' => (isset($concours_info['conc_id']) ? $concours_info['conc_id'] : "0"),
23                                                'conc_name' => (isset($concours_info['conc_name']) ? $concours_info['conc_name'] : "N/A"),
24                                                'conc_descr' => (isset($concours_info['conc_descr']) ? $concours_info['conc_descr'] : "N/A")
25                                                );
26
27        // Try to search on database if the concours is already present to recover name ans description                                 
28                                }
29                        }
30                }
31                closedir($dir);
32                uasort($csvfile, 'name_compare');
33        }
34        return $csvfile;
35}
36
37// Get name and description of a concours with resulte file name
38function get_info_concours_from_csvfile($csvfile = "")
39{
40
41        $query = 'SELECT id_concours as conc_id, CONC.name as conc_name, CONC.descr as conc_descr'
42        .' FROM ' .CONCOURS_RESULT_TABLE
43        .' INNER JOIN '.CONCOURS_TABLE.' AS CONC ON CONC.id = id_concours'
44        .' WHERE file_name = "'.$csvfile .'"'
45        .';';
46
47        $result = pwg_query($query);
48        if ($result)
49                return mysql_fetch_assoc($result);
50        else
51                return false;
52       
53}
54
55
56// check if a result is already present in the database
57function has_result($concours_id)
58{
59        // recover all img_id from the category
60        $query = 'SELECT DISTINCT(id_concours)'
61        .' FROM ' .CONCOURS_RESULT_TABLE
62        .' WHERE id_concours = '.$concours_id .';';
63       
64        $result = pwg_query($query);
65        // For each images
66        if (mysql_fetch_assoc($result))
67                return true;
68        else
69                return false;
70
71}
72// check if a file is already generated and return the link
73function has_file($concours_id)
74{
75        // recover all img_id from the category
76        $query = 'SELECT DISTINCT(file_name)'
77        .' FROM ' .CONCOURS_RESULT_TABLE
78        .' WHERE id_concours = '.$concours_id .';';
79       
80        $result = pwg_query($query);
81        // For each images
82        if ($row = mysql_fetch_assoc($result))
83                return $row['file_name'];
84        else
85                return false;
86
87}
88
89
90// Get list of inactive concours
91// return array with concours id
92function get_inactive_concours()
93{
94        $concours_list=array();
95        $query = '
96                SELECT *
97                FROM ' . CONCOURS_TABLE .'
98                WHERE time_to_sec(TIMEDIFF(begin_date, now())) > 0
99                ORDER BY id
100                ;';
101
102        $result = pwg_query($query);
103//echo $query;
104        while ($row = mysql_fetch_assoc($result))
105        {
106                array_push($concours_list, $row);
107        }
108        return $concours_list;
109}
110
111// Get list of active concours
112// return array with concours id
113function get_active_concours()
114{
115        $concours_list=array();
116        $query = '
117                SELECT *
118                FROM ' . CONCOURS_TABLE .'
119                WHERE time_to_sec(TIMEDIFF(begin_date, now())) < 0
120                AND time_to_sec(TIMEDIFF(now(), end_date)) < 0
121                ORDER BY id
122                ;';
123
124        $result = pwg_query($query);
125//echo $query;
126        while ($row = mysql_fetch_assoc($result))
127        {
128                array_push($concours_list, $row);
129        }
130        return $concours_list;
131}
132
133// Get list of closed concours
134// return array with concours id
135function get_closed_concours()
136{
137        $concours_list=array();
138        $query = '
139                SELECT *
140                FROM ' . CONCOURS_TABLE .'
141                WHERE time_to_sec(TIMEDIFF(now(), end_date)) > 0
142                ORDER BY id
143               
144                '
145//              .'AND id != 0'
146                .';';
147
148        $result = pwg_query($query);
149//echo $query;
150        while ($row = mysql_fetch_assoc($result))
151        {
152                array_push($concours_list, $row);
153        }
154        return $concours_list;
155}
156
157
158function get_html_groups_selection(
159  $groups,
160  $fieldname,
161  $selecteds = array()
162  )
163{
164  global $conf;
165  if (count ($groups) == 0 )
166  {
167    return '';
168  }
169  $output = '<div id="'.$fieldname.'">';
170  $id = 1;
171  foreach ($groups as $group)
172  {
173    $output.=
174
175      '<input type="checkbox" name="'.$fieldname.'[]"'
176      .' id="group_'.$id++.'"'
177      .' value="'.$group['id'].'"'
178      ;
179
180    if (in_array($group['id'], $selecteds))
181    {
182      $output.= ' checked="checked"';
183    }
184
185    $output.=
186      '><label>'
187      .'&nbsp;'. $group['name']
188      .'</label>'
189      ."\n"
190      ;
191  }
192  $output.= '</div>';
193
194  return $output;
195}
196
197
198function get_all_groups()
199{
200$query = '
201SELECT id, name
202  FROM '.GROUPS_TABLE.'
203  ORDER BY name ASC
204;';
205$result = pwg_query($query);
206
207$groups = array();
208  while ($row = mysql_fetch_assoc($result))
209  {
210    array_push($groups, $row);
211  }
212
213  uasort($groups, 'name_compare');
214  return $groups;
215}
216
217?>
Note: See TracBrowser for help on using the repository browser.