public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / admin / listcssassoc.php
100644 238 lines (189 sloc) 7.229 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
/**
* This page is in charge with showing the CSS associated with an element, be it
* a template or anything else.
*
* For more informations about CSS associations please see the header of
* addcssassoc.php
*
* There are compulsory arguments, passed by GET
* - $type  : the type of element
* - $id  : the id of the element.
*
* @since  0.6
* @author  calexico
*/
 
 
 
$CMS_ADMIN_PAGE=1;
 
require_once("../include.php");
 
check_login();
 
include_once("header.php");
global $gCms;
$db =& $gCms->GetDb();
 
#******************************************************************************
# global vars definition
#******************************************************************************
 
# this var is used to store any error that may occur.
$error = "";
 
# this one is used later to store all the css found, because they won't appear in the dropdown
$csslist = array();
 
$type = "";
 
$name = '';
 
#******************************************************************************
# we now get the parameters
#******************************************************************************
 
# getting variables
if (isset($_GET["type"])) $type  = $_GET["type"] ;
else $error = lang('typenotvalid');
 
if (isset($_GET["id"]))  $id  = $_GET["id"] ;
else $error = lang('idnotvalid');
 
$db = cms_db();
 
# if type is template, we get the name
if (isset($type) && "template" == $type)
{
 
  $query = "SELECT template_name FROM ".cms_db_prefix()."templates WHERE id = ?";
  $result = $db->Execute($query, array($id));
 
  if ($result)
  {
    $line = $result->FetchRow();
    $name = $line['template_name'];
  }
  else
  {
    $error = lang('errorretrievingtemplate');
  }
}
 
#******************************************************************************
# first getting all user permissions
#******************************************************************************
  $userid = get_userid();
 
  $modify = check_permission($userid, 'Modify Stylesheet Assoc');
  $delasso = check_permission($userid, 'Remove Stylesheet Assoc');
  $addasso = check_permission($userid, 'Add Stylesheet Assoc');
 
  $query = "SELECT assoc_css_id, css_name FROM ".cms_db_prefix()."css_assoc ca INNER JOIN ".cms_db_prefix()."css ON assoc_css_id = id WHERE assoc_type=? AND assoc_to_id = ? ORDER BY ca.create_date";
  $result = $db->Execute($query, array($type, $id));
 
#******************************************************************************
# displaying erros if any
#******************************************************************************
if (isset($_GET["message"])) {
  $message = preg_replace('/\</','',$_GET['message']);
  echo '<div class="pagemcontainer"><p class="pagemessage">'.$message.'</p></div>';
}
  if ("" != $error)
  {
    echo "<div class=\"pageerrorcontainer\"><p class=\"pageerror\">".$error."</p></div>";
  }
 
  if (!$addasso) {
    echo "<div class=\"pageerrorcontainer\"><p class=\"pageerror\">".lang('noaccessto', array(lang('addcssassociation')))."</p></div>";
  }
 
#******************************************************************************
# now really starting
#******************************************************************************
else {
?>
 
<div class="pagecontainer">
  <?php echo $themeObject->ShowHeader('currentassociations'); ?>
    <div class="pageoverflow">
      <?php echo lang('template')?>: <?php echo '<a href="edittemplate.php?template_id='.$_GET['id'].'" name="edittemplate">'.(isset($name)?$name:"").'</a>';?>
    </div>
 
<?php
 
  # if any css was found.
  if ($result && $result->RecordCount() > 0)
  {
    echo "<table cellspacing=\"0\" class=\"pagetable\">\n";
    echo '<thead>';
    echo "<tr>\n";
    echo "<th>".lang('title')."</th>\n";
    echo "<th class=\"pageicon\">&nbsp;</th>\n";
    echo "</tr>\n";
    echo '</thead>';
    echo '<tbody>';
 
    # this var is used to show each line with different color
    $currow = "row1";
 
    # now showing each line
    while ($one = $result->FetchRow())
    {
 
      # we store ids of css found for them not to appear in the dropdown
      $csslist[] = $one["assoc_css_id"];
    
      echo "<tr class=\"$currow\" onmouseover=\"this.className='".$currow.'hover'."';\" onmouseout=\"this.className='".$currow."';\">\n";    
      echo "<td><a href=\"editcss.php?css_id=".$one["assoc_css_id"]."&amp;from=templatecssassoc&amp;templateid=".$id."\">".$one["css_name"]."</a></td>\n";
 
      # if user has right to delete
      if ($delasso)
      {
        echo "<td><a href=\"deletecssassoc.php?id=$id&amp;css_id=".$one["assoc_css_id"]."&amp;type=$type\" onclick=\"return confirm('".lang('deleteassociationconfirm', $one["css_name"])."');\">";
                echo $themeObject->DisplayImage('icons/system/delete.gif', lang('delete'),'','','systemicon');
                echo "</a></td>\n";
      }
      else
      {
        echo "<td>&nbsp;</td>";
      }
 
      echo "</tr>\n";
 
      ("row1" == $currow) ? $currow="row2" : $currow="row1";
 
    } ## foreach
 
    echo '</tbody>';
    echo "</table>\n";
 
  } # end of if result
  
  # this var is used to store the css ids that should not appear in the
  # dropdown
  $notinto = "";
 
  foreach($csslist as $key)
  {
    $notinto .= "$key,";
  }
  $notinto = substr($notinto, 0, strlen($notinto) - 1);
 
  # this var contains the dropdown
  $dropdown = "";
  $result = '';
 
  # we generate the dropdown
  if ("" == $notinto)
  {
    $query = "SELECT * FROM ".cms_db_prefix()."css ORDER BY css_name";
  }
  else
  {
    $query = "SELECT * FROM ".cms_db_prefix()."css WHERE id NOT IN (".$notinto.") ORDER BY css_name";
  }
  $result = $db->Execute($query);
 
  if ($result && $result->RecordCount() > 0)
  {
    $form = "<form action=\"addcssassoc.php\" method=\"post\">";
  
    $dropdown = "<select name=\"css_id\">\n";
    while ($line = $result->FetchRow())
    {
      $dropdown .= "<option value=\"".$line["id"]."\">".$line["css_name"]."</option>\n";
    }
    $dropdown .= "</select>";
 
    echo $form.'<div class="pageoverflow"><p class="pageoptions">'.$dropdown.' ';
?>
    <input type="hidden" name="id" value="<?php echo $id?>" />
    <input type="hidden" name="type" value="<?php echo $type?>" />
    <input type="submit" value="<?php echo lang('addcss')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover';" onmouseout="this.className='pagebutton';" />
    </p>
    </div>
    </form>
 
<?php
    } # end of showing form
  echo '</div>';
}
echo '<p class="pageback"><a class="pageback" href="'.$themeObject->BackUrl().'">&#171; '.lang('back').'</a></p>';
 
include_once("footer.php");
 
# vim:ts=4 sw=4 noet
?>