source: extensions/WiredForSound/admin/add_page_on_index.php @ 3302

Last change on this file since 3302 was 3302, checked in by patdenice, 15 years ago

New extension added:
Wired For Sound (2.0.b)

File size: 3.6 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$back_url = $_GET['backurl'];
11$volume = '';
12
13// Changement de repertoire
14if (isset($_POST['change_path']))
15{
16  $mp3_path = $_POST['mp3_path'];
17  if (strrpos($mp3_path , '/') != (strlen($mp3_path) - 1))
18  {
19    $mp3_path .= '/';
20  }
21}
22
23// Suppression de l'association
24if (isset($_POST['delete']))
25{
26  pwg_query('DELETE FROM ' . WFS_IMG_CAT_TABLE . ' WHERE image_id IS NULL AND cat_id = ' . $cat_id . ';');
27}
28
29// Enregistrement de l'association
30if (isset($_POST['submit']) and !empty($_POST['mp3_select']))
31{
32  pwg_query('DELETE FROM ' . WFS_IMG_CAT_TABLE . ' WHERE image_id IS NULL AND cat_id = ' . $cat_id . ';');
33  if (empty($_POST['volume'])) $_POST['volume'] = 'NULL';
34
35  $q = 'SELECT id FROM ' . WFS_SOUNDS_TABLE . ' WHERE file = "' . $_POST['mp3_select'] . '";';
36  $result = mysql_fetch_assoc(pwg_query($q));
37
38  if (empty($result))
39  {
40    $q = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id  FROM ' . WFS_SOUNDS_TABLE . ' ;';
41    list($next_element_id) = mysql_fetch_array(pwg_query($q));
42    $q = 'INSERT INTO ' . WFS_SOUNDS_TABLE . ' ( id , file ) VALUES ( ' . $next_element_id . ' , "' . $_POST['mp3_select'] . '");';
43    pwg_query($q);
44    $result['id'] = $next_element_id;
45  }
46
47  $q = 'INSERT INTO ' . WFS_IMG_CAT_TABLE . ' ( image_id , cat_id , sound_id , volume )
48VALUES ( NULL , ' . $cat_id . ' , ' . $result['id'] . ' , ' . $_POST['volume'] . ');';
49  pwg_query($q);
50}
51
52// Recupération des données de la table
53$q = 'SELECT sound.file AS sound, ic.volume AS volume
54FROM ' . WFS_SOUNDS_TABLE . ' AS sound
55INNER JOIN ' . WFS_IMG_CAT_TABLE . ' AS ic
56ON sound.id = ic.sound_id
57WHERE ic.cat_id = ' . $cat_id . ' AND ic.image_id IS NULL;';
58$result = mysql_fetch_assoc(pwg_query($q));
59
60// Bouton de suppression
61if (!empty($result))
62{
63  $template->assign('delete', true);
64}
65
66// Dossier mp3
67if (isset($result['sound']) and !isset($_POST['change_path']) and !isset($wfs_param[2]))
68{
69  $mp3_path = substr($result['sound'] , 0 , strrpos($result['sound'] , '/') + 1);
70}
71 
72// Volume
73if (isset($result['volume']))
74{
75  $volume = $result['volume'];
76}
77
78// Liste des mp3 du dossier spécifié
79if (is_dir('./' . $mp3_path) and $contents = opendir($mp3_path))
80{
81  $options[] = '----------------';
82  $selected = 0;
83  while (($node = readdir($contents)) !== false)
84  {
85    if (is_file('./' . $mp3_path . $node))
86    {
87      $extension = strtolower(get_extension($node));
88      if ($extension == 'mp3')
89      {
90        $value = $mp3_path . $node;
91        if (isset($result['sound']) and $result['sound'] == $value)
92        {
93          $selected = $value;
94        }
95        $options[$value] = $node;
96      }
97    }
98  }
99  closedir($contents);
100  // Erreur si pas de mp3
101  if (count($options) == 1)
102  {
103    array_push($page['errors'], l10n('wfs_no_mp3'));
104  }
105  else
106  {
107    $template->assign('mp3_select', array(
108      'OPTIONS' => $options,
109      'SELECTED' => $selected));
110  }
111}
112else
113{
114  array_push($page['errors'], l10n('wfs_no_path'));
115}
116
117// Affichage du fichier associé
118if (isset($result['sound']))
119{
120  $template->assign('ACTUAL_FILE', $result['sound']);
121}
122
123$template->assign(array(
124  'MP3_PATH' => $mp3_path,
125  'BACK' => $back_url,
126  'VOLUME' => $volume));
127
128$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/../template/add_page_on_index.tpl');
129$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
130
131?>
Note: See TracBrowser for help on using the repository browser.