source: extensions/WiredForSound/admin/add_page_on_picture.php @ 27153

Last change on this file since 27153 was 21793, checked in by ddtddt, 11 years ago

[extensions] - WiredForSound - change to 2.5

File size: 4.5 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4load_language('plugin.lang', WFS_PATH);
5
6$wfs_conf = explode(',' , $conf['wired_for_sound']);
7$mp3_path = $wfs_conf[0];
8
9$cat_id = $_GET['catid'];
10$img_id = $_GET['imgid'];
11$back_url = $_GET['backurl'];
12$volume = '';
13
14function get_wfs_from_table()
15{
16  global $img_id, $cat_id;
17  if (empty($cat_id))
18  {
19    $clause = 'cat_id IS NULL';
20  }
21        else
22  {
23    $clause = '(cat_id = ' . $cat_id . ' OR cat_id IS NULL)';
24  }
25        $q = 'SELECT sound.id AS id, sound.file AS sound, ic.volume AS volume, ic.cat_id AS cat_id
26FROM ' . WFS_SOUNDS_TABLE . ' AS sound
27INNER JOIN ' . WFS_IMG_CAT_TABLE . ' AS ic
28ON sound.id = ic.sound_id
29WHERE ic.image_id = ' . $img_id . '  AND ' . $clause . '
30ORDER BY ic.cat_id DESC;';
31    return pwg_db_fetch_assoc(pwg_query($q));
32}
33
34function delete_wfs_from_table($param)
35{
36  global $img_id, $cat_id;
37  if (!empty($param))
38  {
39    pwg_query('DELETE FROM ' . WFS_IMG_CAT_TABLE . ' WHERE image_id = ' . $img_id . ' AND cat_id = ' . $cat_id . ';');
40  }
41  else
42  {
43    pwg_query('DELETE FROM ' . WFS_IMG_CAT_TABLE . ' WHERE image_id = ' . $img_id . ' AND cat_id IS NULL;');
44  }
45}
46
47// Changement de repertoire
48if (isset($_POST['change_path']))
49{
50  $mp3_path = $_POST['mp3_path'];
51  if (strrpos($mp3_path , '/') != (strlen($mp3_path) - 1))
52  {
53    $mp3_path .= '/';
54  }
55}
56
57// Suppression de l'association
58if (isset($_POST['delete']))
59{
60  $result = get_wfs_from_table();
61  delete_wfs_from_table($result['cat_id']);
62}
63
64// Enregistrement de l'association
65if (isset($_POST['submit']) and !empty($_POST['mp3_select']))
66{
67  // Suppression des eventuelles données existantes
68  if (!isset($_POST['assign_all']))
69  {
70    $_POST['assign_all'] = '';
71  }
72  delete_wfs_from_table($_POST['assign_all']);
73
74  $cat_write = $cat_id;
75  if (empty($_POST['assign_all'])) $cat_write = 'NULL';
76  if (empty($_POST['volume'])) $_POST['volume'] = 'NULL';
77
78  // Ecriture dans la table
79  $q = 'SELECT id FROM ' . WFS_SOUNDS_TABLE . ' WHERE file = "' . $_POST['mp3_select'] . '";';
80  $result = pwg_db_fetch_assoc(pwg_query($q));
81  if (empty($result))
82  {
83    $q = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id  FROM ' . WFS_SOUNDS_TABLE . ' ;';
84    list($next_element_id) = pwg_db_fetch_row(pwg_query($q));
85    $q = 'INSERT INTO ' . WFS_SOUNDS_TABLE . ' ( id , file ) VALUES ( ' . $next_element_id . ' , "' . $_POST['mp3_select'] . '");';
86    pwg_query($q);
87    $result['id'] = $next_element_id;
88  }
89  $q = 'INSERT INTO ' . WFS_IMG_CAT_TABLE . ' ( image_id , cat_id , sound_id , volume )
90VALUES (' . $img_id . ' , ' . $cat_write . ' , ' . $result['id'] . ' , ' . $_POST['volume'] . ');';
91  pwg_query($q);
92}
93
94// Récupération des données de la table
95$result = get_wfs_from_table();
96
97// Bouton de suppression
98if (!empty($result))
99{
100  $template->assign('delete', true);
101}
102
103// Dossier mp3
104if (isset($result['sound']) and !isset($_POST['change_path']) and !isset($wfs_param[2]))
105{
106  $mp3_path = substr($result['sound'] , 0 , strrpos($result['sound'] , '/') + 1);
107}
108
109// Volume
110if (isset($result['volume']))
111{
112  $volume = $result['volume'];
113}
114
115// Liste des mp3 du dossier spécifié
116if (is_dir('./' . $mp3_path) and $contents = opendir($mp3_path))
117{
118  $options[] = '----------------';
119  $selected = 0;
120  while (($node = readdir($contents)) !== false)
121  {
122    if (is_file('./' . $mp3_path . $node))
123    {
124      $extension = strtolower(get_extension($node));
125      if ($extension == 'mp3')
126      {
127        $value = $mp3_path . $node;
128        if (isset($result['sound']) and $result['sound'] == $value)
129        {
130          $selected = $value;
131        }
132        $options[$value] = $node;
133      }
134    }
135  }
136  closedir($contents);
137  // Erreur si pas de mp3
138  if (count($options) == 1)
139  {
140    array_push($page['errors'], l10n('wfs_no_mp3'));
141  }
142  else
143  {
144    $template->assign('mp3_select', array(
145      'OPTIONS' => $options,
146      'SELECTED' => $selected));
147  }
148}
149else
150{
151  array_push($page['errors'], l10n('wfs_no_path'));
152}
153
154// Affichage du fichier associé
155if (isset($result['sound']))
156{
157        if (isset($result['cat_id']))
158  {
159    $assign_all = l10n('wfs_only_this_cat');
160  }
161        else
162  {
163    $assign_all = l10n('wfs_all_cat');
164  }
165  $template->assign(array(
166    'ACTUAL_FILE' => $result['sound'],
167    'ASSIGN_ALL' => $assign_all));
168}
169
170$template->assign(array(
171  'MP3_PATH' => $mp3_path,
172  'BACK' => $back_url,
173  'VOLUME' => $volume));
174
175$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/../template/add_page_on_picture.tpl');
176$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
177
178?>
Note: See TracBrowser for help on using the repository browser.