1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | load_language('plugin.lang', AP_PATH); |
---|
5 | $ap_conf = explode(',' , $conf['additional_pages']); |
---|
6 | $edited_page = array(); |
---|
7 | $page_title = l10n('ap_create'); |
---|
8 | |
---|
9 | if (isset($_GET['saved']) and isset($_GET['edit'])) |
---|
10 | { |
---|
11 | array_push($page['infos'], sprintf(l10n('ap_saved_page') , $_GET['edit'])); |
---|
12 | } |
---|
13 | |
---|
14 | // Suppression |
---|
15 | if (isset($_POST['delete']) and isset($_GET['edit'])) |
---|
16 | { |
---|
17 | pwg_query('DELETE FROM ' . ADD_PAGES_TABLE . ' WHERE id = ' . $_GET['edit'] . ';'); |
---|
18 | array_push($page['infos'], l10n('ap_deleted_page')); |
---|
19 | @unlink(AP_PATH . 'backup/' . $_GET['edit'] . '.txt'); |
---|
20 | return; |
---|
21 | } |
---|
22 | |
---|
23 | // Enregistrement |
---|
24 | if (isset($_POST['save'])) |
---|
25 | { |
---|
26 | $group_access = (!empty($_POST['groups']) ? implode(',', $_POST['groups']) : ''); |
---|
27 | $user_access = (!empty($_POST['users']) ? implode(',', $_POST['users']) : ''); |
---|
28 | if (empty($_POST['name'])) |
---|
29 | { |
---|
30 | array_push($page['errors'], l10n('ap_no_name')); |
---|
31 | $edited_page['title'] = ''; |
---|
32 | $edited_page['pos'] = $_POST['pos']; |
---|
33 | $edited_page['text'] = stripslashes($_POST['ap_content']); |
---|
34 | $edited_page['group'] = (!empty($_POST['groups']) ? $_POST['groups'] : array()); |
---|
35 | $edited_page['user'] = (!empty($_POST['users']) ? $_POST['users'] : array()); |
---|
36 | } |
---|
37 | else |
---|
38 | { |
---|
39 | $PageTitle = $_POST['name']; |
---|
40 | if (!empty($group_access)) |
---|
41 | { |
---|
42 | $PageTitle .= '/group_id=' . $group_access ; |
---|
43 | } |
---|
44 | if ($ap_conf[7] == 'on') |
---|
45 | { |
---|
46 | $PageTitle .= '/user_id=' . $user_access ; |
---|
47 | } |
---|
48 | if (isset($_GET['edit'])) |
---|
49 | { |
---|
50 | $next_element_id = $_GET['edit']; |
---|
51 | pwg_query('DELETE FROM ' . ADD_PAGES_TABLE . ' WHERE id = ' . $_GET['edit'] . ';'); |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | $q = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id FROM ' . ADD_PAGES_TABLE . ' ;'; |
---|
56 | list($next_element_id) = mysql_fetch_array(pwg_query($q)); |
---|
57 | } |
---|
58 | if ($_POST['pos'] == '') $_POST['pos'] = 'NULL'; |
---|
59 | $q = 'INSERT INTO ' . ADD_PAGES_TABLE . ' ( id , pos , lang , title , text ) |
---|
60 | VALUES (' . $next_element_id . ' , ' . $_POST['pos'] . ' , "' . $_POST['lang'] . '" , "' . $PageTitle . '" , "' . $_POST['ap_content'] . '");'; |
---|
61 | pwg_query($q); |
---|
62 | |
---|
63 | // Enregistrement du fichier de sauvegarde |
---|
64 | $sav_file = @fopen(AP_PATH . 'backup/' . $next_element_id . '.txt', "w"); |
---|
65 | @fwrite($sav_file, "Title: " . $_POST['name'] . " |
---|
66 | Position: " . $_POST['pos'] . " |
---|
67 | Language: " . $_POST['lang'] . " |
---|
68 | |
---|
69 | " . $_POST['ap_content']); |
---|
70 | @fclose($sav_file); |
---|
71 | |
---|
72 | if (isset($ap_conf[4]) and $ap_conf[4] == 'on') |
---|
73 | { |
---|
74 | redirect(get_root_url() . 'index.php?/additional_page/' . $next_element_id); |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | redirect(get_root_url() . 'admin.php?page=plugin§ion=' . AP_DIR . '%2Fadmin%2Fadd_page.php&saved=1&edit=' . $next_element_id); |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | // Chargement des données |
---|
84 | if (isset($_GET['edit'])) |
---|
85 | { |
---|
86 | $q = 'SELECT id , pos , lang , title , text |
---|
87 | FROM ' . ADD_PAGES_TABLE . ' |
---|
88 | WHERE id = ' . $_GET['edit'] . ';'; |
---|
89 | $edited_page = mysql_fetch_assoc(pwg_query($q)); |
---|
90 | $page_title = l10n('ap_modify'); |
---|
91 | // Utilisateurs autorisés |
---|
92 | if (strpos($edited_page['title'] , '/user_id=')) |
---|
93 | { |
---|
94 | $array = explode('/user_id=' , $edited_page['title']); |
---|
95 | $edited_page['title'] = $array[0]; |
---|
96 | $edited_page['user'] = explode(',', $array[1]); |
---|
97 | } |
---|
98 | // Groupes autorisés |
---|
99 | if (strpos($edited_page['title'] , '/group_id=')) |
---|
100 | { |
---|
101 | $array = explode('/group_id=' , $edited_page['title']); |
---|
102 | $edited_page['title'] = $array[0]; |
---|
103 | $edited_page['group'] = explode(',', $array[1]); |
---|
104 | } |
---|
105 | // Lien de suppression |
---|
106 | $template->assign('delete', true); |
---|
107 | } |
---|
108 | |
---|
109 | // Selection des langues |
---|
110 | $options['ALL'] = l10n('ap_all_lang'); |
---|
111 | $selected = 'ALL'; |
---|
112 | foreach (get_languages() as $language_code => $language_name) |
---|
113 | { |
---|
114 | $options[$language_code] = $language_name; |
---|
115 | if (isset($edited_page['lang']) and $edited_page['lang'] == $language_code) |
---|
116 | { |
---|
117 | $selected = $language_code; |
---|
118 | } |
---|
119 | } |
---|
120 | $template->assign('lang', array( |
---|
121 | 'OPTIONS' => $options, |
---|
122 | 'SELECTED' => $selected)); |
---|
123 | |
---|
124 | // Selection des groupes |
---|
125 | if (isset($ap_conf[6]) and $ap_conf[6] == 'on') |
---|
126 | { |
---|
127 | include_once(AP_PATH . 'admin/functions_groups.php'); |
---|
128 | $template->assign('GROUPSELECTION', get_html_groups_selection(get_all_groups(), 'groups', (!empty($edited_page['group']) ? $edited_page['group'] : array()))); |
---|
129 | } |
---|
130 | |
---|
131 | // Selection des utilisateurs |
---|
132 | if (isset($ap_conf[7]) and $ap_conf[7] == 'on') |
---|
133 | { |
---|
134 | $selected_users = (isset($edited_page['user']) ? $edited_page['user'] : array('guest', 'generic', 'normal')); |
---|
135 | $template->assign('user_perm', array( |
---|
136 | 'GUEST' => (in_array('guest', $selected_users) ? 'checked="checked"' : ''), |
---|
137 | 'GENERIC' => (in_array('generic', $selected_users) ? 'checked="checked"' : ''), |
---|
138 | 'NORMAL' => (in_array('normal', $selected_users) ? 'checked="checked"' : ''))); |
---|
139 | } |
---|
140 | |
---|
141 | // Chargement des données pour l'édition |
---|
142 | if (!empty($edited_page)) |
---|
143 | { |
---|
144 | $template->assign(array( |
---|
145 | 'NAME' => $edited_page['title'], |
---|
146 | 'POS' => $edited_page['pos'], |
---|
147 | 'CONTENT' => $edited_page['text'])); |
---|
148 | } |
---|
149 | |
---|
150 | // Parametrage du template |
---|
151 | $template->assign('AP_TITLE', $page_title); |
---|
152 | |
---|
153 | $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/add_page.tpl'); |
---|
154 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
155 | |
---|
156 | ?> |
---|