source: extensions/Comments_Access_Manager/admin.php

Last change on this file was 21117, checked in by Eric, 11 years ago

Next version is 2.5.0 :
Compliance with Piwigo 2.5
Code refactory : Change config variables to assoc array and $_POST vars control before writing conf in database - Thx to flop25 for his advices ;-)
Update zh_CN, thanks to : winson and dennisyan
Add pt_BR, thanks to : flaviove

  • Property svn:eol-style set to LF
File size: 6.3 KB
Line 
1<?php
2
3global $lang, $conf, $errors;
4
5if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
6// +-----------------------------------------------------------------------+
7// | Check Access and exit when user status is not ok                      |
8// +-----------------------------------------------------------------------+
9check_status(ACCESS_ADMINISTRATOR);
10
11if (!defined('CM_PATH')) define('CM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
12
13//ini_set('error_reporting', E_ALL);
14//ini_set('display_errors', true);
15
16include_once (PHPWG_ROOT_PATH.'/include/constants.php');
17
18load_language('plugin.lang', CM_PATH);
19
20
21// +-----------------------------------------------------------------------+
22// |                      Getting plugin version                           |
23// +-----------------------------------------------------------------------+
24$plugin =  CM_Infos(CM_PATH);
25$version = $plugin['version'];
26
27
28// *************************************************************************
29// +-----------------------------------------------------------------------+
30// |                           Plugin Config                               |
31// +-----------------------------------------------------------------------+
32// *************************************************************************
33
34        if (isset($_POST['submit']) and isset($_POST['CM_No_Comment_Anonymous']) and isset($_POST['CM_GroupComm']) and isset($_POST['CM_GroupValid1']) and isset($_POST['CM_GroupValid2']))
35  {
36    $newconf_CM['CMVersion'] = $version;
37    $newconf_CM['CM_No_Comment_Anonymous'] = (isset($_POST['CM_No_Comment_Anonymous']) ? $_POST['CM_No_Comment_Anonymous'] : 'false');
38    $newconf_CM['CM_GROUPCOMM'] = (isset($_POST['CM_GroupComm']) ? $_POST['CM_GroupComm'] : 'false');
39    $newconf_CM['CM_ALLOWCOMM_GROUP'] = (isset($_POST['CM_AllowComm_Group']) ? $_POST['CM_AllowComm_Group'] : '');
40    $newconf_CM['CM_GROUPVALID1'] = (isset($_POST['CM_GroupValid1']) ? $_POST['CM_GroupValid1'] : 'false');
41    $newconf_CM['CM_VALIDCOMM1_GROUP'] = (isset($_POST['CM_ValidComm_Group1']) ? $_POST['CM_ValidComm_Group1'] : '');
42    $newconf_CM['CM_GROUPVALID2'] = (isset($_POST['CM_GroupValid2']) ? $_POST['CM_GroupValid2'] : 'false');
43    $newconf_CM['CM_VALIDCOMM2_GROUP'] = (isset($_POST['CM_ValidComm_Group2']) ? $_POST['CM_ValidComm_Group2'] : '');
44
45    $conf['CommentsManager'] = serialize($newconf_CM);
46
47    conf_update_param('CommentsManager', pwg_db_real_escape_string($conf['CommentsManager']));
48
49                array_push($page['infos'], l10n('CM_save_config'));
50  }
51
52  $conf_CM = unserialize($conf['CommentsManager']);
53
54
55  //Group setting
56  $groups[-1] = '---------';
57  $AllowComm = -1;
58  $ValidComm1 = -1;
59  $ValidComm2 = -1;
60       
61  //Check groups list in database
62  $query = '
63SELECT id, name
64FROM '.GROUPS_TABLE.'
65ORDER BY name ASC
66;';
67       
68  $result = pwg_query($query);
69       
70  while ($row = pwg_db_fetch_assoc($result))
71  {
72    $groups[$row['id']] = $row['name'];
73
74    //configuration value for users group allowed to post comments
75    if (isset($conf_CM['CM_ALLOWCOMM_GROUP']) and $conf_CM['CM_ALLOWCOMM_GROUP'] == $row['id'])
76                {
77                $AllowComm = $row['id'];
78                }
79
80    //configuration value for users group allowed to post comments
81    if (isset($conf_CM['CM_VALIDCOMM1_GROUP']) and $conf_CM['CM_VALIDCOMM1_GROUP'] == $row['id'])
82                {
83                $ValidComm1 = $row['id'];
84                }
85
86    //configuration value for users group allowed to post comments
87    if (isset($conf_CM['CM_VALIDCOMM2_GROUP']) and $conf_CM['CM_VALIDCOMM2_GROUP'] == $row['id'])
88                {
89                $ValidComm2 = $row['id'];
90                }
91  }
92
93  //Template initialization for allowed group for comments
94  $template->assign(
95    'AllowComm_Group',
96                array(
97      'group_options'=> $groups,
98      'group_selected' => $AllowComm
99                        )
100        );
101  //Template initialization for validated group for comments
102  $template->assign(
103    'ValidComm_Group1',
104                array(
105      'group_options'=> $groups,
106      'group_selected' => $ValidComm1
107                        )
108        );
109  //Template initialization for validated group for comments
110  $template->assign(
111    'ValidComm_Group2',
112                array(
113      'group_options'=> $groups,
114      'group_selected' => $ValidComm2
115                        )
116        );
117
118
119  // Template initialization for forms and data
120  $themeconf=$template->get_template_vars('themeconf');
121  $CM_theme=$themeconf['id'];
122
123  $template->assign(
124    array(
125    'CM_PATH'                       => CM_PATH,
126    'CM_CFA'                        => $conf['comments_forall'],
127    'CM_VALIDATION'                 => $conf['comments_validation'],
128    'CM_VERSION'                    => $conf_CM['CMVersion'],
129                'CM_NO_COMMENT_ANO_TRUE'        => $conf_CM['CM_No_Comment_Anonymous']=='true' ?  'checked="checked"' : '' ,
130                'CM_NO_COMMENT_ANO_FALSE'       => $conf_CM['CM_No_Comment_Anonymous']=='false' ?  'checked="checked"' : '' ,
131    'CM_GROUPCOMM_TRUE'             => $conf_CM['CM_GROUPCOMM']=='true' ?  'checked="checked"' : '' ,
132    'CM_GROUPCOMM_FALSE'            => $conf_CM['CM_GROUPCOMM']=='false' ?  'checked="checked"' : '' ,
133    'CM_ALLOWCOMM_GROUP'            => $conf_CM['CM_ALLOWCOMM_GROUP'],
134    'CM_GROUPVALID1_TRUE'           => $conf_CM['CM_GROUPVALID1']=='true' ?  'checked="checked"' : '' ,
135    'CM_GROUPVALID1_FALSE'          => $conf_CM['CM_GROUPVALID1']=='false' ?  'checked="checked"' : '' ,
136    'CM_VALIDCOMM1_GROUP'           => $conf_CM['CM_VALIDCOMM1_GROUP'],
137    'CM_GROUPVALID2_TRUE'           => $conf_CM['CM_GROUPVALID2']=='true' ?  'checked="checked"' : '' ,
138    'CM_GROUPVALID2_FALSE'          => $conf_CM['CM_GROUPVALID2']=='false' ?  'checked="checked"' : '' ,
139    'CM_VALIDCOMM2_GROUP'           => $conf_CM['CM_VALIDCOMM2_GROUP'],
140    )
141  );
142
143
144// +-----------------------------------------------------------------------+
145// |                             errors display                            |
146// +-----------------------------------------------------------------------+
147  if (isset ($errors) and count($errors) != 0)
148  {
149          $template->assign('errors',array());
150          foreach ($errors as $error)
151          {
152                  array_push($page['errors'], $error);
153                }
154        }
155
156// +-----------------------------------------------------------------------+
157// |                           templates display                           |
158// +-----------------------------------------------------------------------+
159  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/admin.tpl');
160  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
161?>
Note: See TracBrowser for help on using the repository browser.