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 / listtemplates.php
100644 277 lines (243 sloc) 8.857 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?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$
 
$CMS_ADMIN_PAGE=1;
 
require_once("../include.php");
 
check_login();
 
include_once("header.php");
global $gCms;
$db =& $gCms->GetDb();
 
if (isset($_GET["message"]))
{
  $message = preg_replace('/\</','',$_GET['message']);
  echo '<div class="pagemcontainer"><p class="pagemessage">'.$message.'</p></div>';
}
 
?>
 
<form action="multitemplate.php" method="post">
<div class="pagecontainer">
  <div class="pageoverflow">
 
<?php
 
  $userid  = get_userid();
  $current_user = CmsLogin::get_current_user();
  $add = CmsAcl::check_core_permission('Add', $current_user, 'Template');
  $edit = check_permission($userid, 'Modify Templates');
  $all = check_permission($userid, 'Modify Any Page');
  $remove  = check_permission($userid, 'Remove Templates');
  
  global $gCms;
  $templateops = $gCms->GetTemplateOperations();
 
  if ($all && isset($_GET["action"]) && $_GET["action"] == "setallcontent")
  {
    if (isset($_GET["template_id"]))
    {
      $query = "UPDATE ".cms_db_prefix()."content SET template_id = ?";
      $result = $db->Execute($query, array($_GET['template_id']));
      if ($result)
      {
        $query = "UPDATE ".cms_db_prefix()."content SET modified_date = ".$db->DBTimeStamp(time());
        $db->Execute($query);
        echo '<p>'.lang('allpagesmodified').'</p>';
      }
      else
      {
        echo '<p class="error">'.lang('errorupdatingpages').'</p>';
      }
    }
  }
 
  if (isset($_GET['setdefault']))
  {
    $templatelist = cmsms()->template->find_all();
    foreach ($templatelist as $onetemplate)
    {
      if ($onetemplate->id == $_GET['setdefault'])
      {
        $onetemplate->default = 1;
        $onetemplate->active = 1;
        $result = $onetemplate->save();
        if (!$result)
        {
          echo '<ul>';
          foreach ($onetemplate->validation_errors as $err)
          {
            echo '<li>'.$err.'</li>';
          }
          echo '</ul>';
        }
      }
      else
      {
        $onetemplate->default = 0;
        $result = $onetemplate->save();
        if (!$result)
        {
          echo '<ul>';
          foreach ($onetemplate->validation_errors as $err)
          {
            echo '<li>'.$err.'</li>';
          }
          echo '</ul>';
        }
      }
    }
  }
 
  if (isset($_GET['setactive']) || isset($_GET['setinactive']))
  {
    $theid = '';
    $active = false;
    if (isset($_GET['setactive']))
    {
      $theid = $_GET['setactive'];
      $active = true;
    }
    if (isset($_GET['setinactive']))
    {
      $theid = $_GET['setinactive'];
    }
    $thetemplate = cmsms()->template->find_by_id($theid);
    if ($thetemplate)
    {
      $thetemplate->active = $active;
      $thetemplate->save();
    }
  }
 
  $templatelist = $templateops->LoadTemplates();
  
  $page = 1;
  if (isset($_GET['page'])) $page = $_GET['page'];
  $limit = 20;
  if (count($templatelist) > $limit)
  {
    echo "<p class=\"pageshowrows\">".pagination($page, count($templatelist), $limit)."</p>";
  }
  echo $themeObject->ShowHeader('currenttemplates').'</div>';
  if ($templatelist && count($templatelist) > 0) {
 
    echo '<table cellspacing="0" class="pagetable">';
    echo '<thead>';
    echo "<tr>\n";
    echo '<th class="pagew50">'.lang('template').'</th>';
    echo "<th class=\"pagepos\">".lang('default')."</th>\n";
    echo "<th class=\"pagepos\">".lang('active')."</th>\n";
    if ($edit)
      echo "<th class=\"pagepos\">&nbsp;</th>\n";
    echo "<th class=\"pageicon\">&nbsp;</th>\n";
    if ($add)
      echo "<th class=\"pageicon\">&nbsp;</th>\n";
    if ($remove)
      echo "<th class=\"pageicon\">&nbsp;</th>\n";
    if ($all)
      echo "<th class=\"pageicon\">&nbsp;</th>\n";
    echo "<th class=\"pageicon\">&nbsp;</th>\n";
 
    echo "</tr>\n";
    echo '</thead>';
    echo '<tbody>';
 
    $currow = "row1";
    $counter=0;
 
    foreach ($templatelist as $onetemplate)
    {
      // construct true/false button images
            $image_true = "<a href=\"listtemplates.php?setinactive=".$onetemplate->id."\">".$themeObject->DisplayImage('icons/system/true.gif', lang('setfalse'),'','','systemicon')."</a>";
            $image_false = "<a href=\"listtemplates.php?setactive=".$onetemplate->id."\">".$themeObject->DisplayImage('icons/system/false.gif', lang('settrue'),'','','systemicon')."</a>";
      $default_true =$themeObject->DisplayImage('icons/system/true.gif', lang('true'),'','','systemicon');
      $default_false ="<a href=\"listtemplates.php?setdefault=".$onetemplate->id."\">".$themeObject->DisplayImage('icons/system/false.gif', lang('settrue'),'','','systemicon')."</a>";
 
      if ($counter < $page*$limit && $counter >= ($page*$limit)-$limit) {
         echo "<tr class=\"$currow\" onmouseover=\"this.className='".$currow.'hover'."';\" onmouseout=\"this.className='".$currow."';\">\n";
        echo "<td><a href=\"edittemplate.php?template_id=".$onetemplate->id."\">".$onetemplate->name."</a></td>\n";
        echo "<td class=\"pagepos\">".($onetemplate->default == 1?$default_true:$default_false)."</td>\n";
        if ($onetemplate->default)
          echo "<td class=\"pagepos\">".$themeObject->DisplayImage('icons/system/true.gif', lang('true'),'','','systemicon')."</td>\n";
        else
          echo "<td class=\"pagepos\">".($onetemplate->active == 1?$image_true:$image_false)."</td>\n";
 
        # set template to all content
        if ($all)
          echo "<td class=\"pagepos\"><a href=\"listtemplates.php?action=setallcontent&amp;template_id=".$onetemplate->id."\" onclick=\"return confirm('".lang('setallcontentconfirm')."');\">".lang('setallcontent')."</a></td>\n";
 
        # view css association
        echo "<td class=\"icons_wide\"><a href=\"assignstylesheets.php?type=template&amp;template_id=".$onetemplate->id."\">";
                echo $themeObject->DisplayImage('icons/system/css.gif', lang('attachstylesheets'),'','','systemicon');
                echo "</a></td>\n";
 
        # add new template
        if ($add)
        {
         echo "<td class=\"icons_wide\"><a href=\"copytemplate.php?template_id=".$onetemplate->id."&amp;template_name=".urlencode($onetemplate->name)."\">";
                    echo $themeObject->DisplayImage('icons/system/copy.gif', lang('copy'),'','','systemicon');
                    echo "</a></td>\n";
        }
 
        # edit template
        if ($edit)
        {
          echo "<td class=\"icons_wide\"><a href=\"edittemplate.php?template_id=".$onetemplate->id."\">";
                    echo $themeObject->DisplayImage('icons/system/edit.gif', lang('edit'),'','','systemicon');
                    echo "</a></td>\n";
        }
 
        # remove template
        if ($remove)
        {
          echo "<td class=\"icons_wide\">";
          if ($onetemplate->default)
          {
            echo '&nbsp;';
          }
          else
          {
            echo "<a href=\"deletetemplate.php?template_id=".$onetemplate->id."\" onclick=\"return confirm('".lang('deleteconfirm', $onetemplate->name)."');\">";
            echo $themeObject->DisplayImage('icons/system/delete.gif', lang('delete'),'','','systemicon');
            echo "</a>";
          }
          echo "</td>\n";
        }
        if ($onetemplate->default)
          echo '<td>&nbsp;</td>';
        else
          echo '<td><input type="checkbox" name="multitemplate-'.$onetemplate->id.'" /></td>';
        echo "</tr>\n";
 
        ($currow=="row1"?$currow="row2":$currow="row1");
 
      }
      $counter++;
    }
 
    echo '</tbody>';
    echo "</table>\n";
 
  }
 
if ($add) {
?>
  <div class="pageoptions">
    <p class="pageoptions">
      <span style="float: left;">
        <a href="addtemplate.php">
          <?php
            echo $themeObject->DisplayImage('icons/system/newobject.gif', lang('addtemplate'),'','','systemicon').'</a>';
            echo ' <a class="pageoptions" href="addtemplate.php">'.lang("addtemplate");
          ?>
        </a>
      </span>
      <span style="margin-right: 30px; float: right; text-align: right">
        <?php echo lang("selecteditems"); ?>: <select name="multiaction">
        <option value="delete"><?php echo lang('delete') ?></option>
        <option value="active"><?php echo lang('active') ?></option>
        <option value="inactive"><?php echo lang('inactive') ?></option>
        </select>
        <input type="submit" value="<?php echo lang('submit') ?>" />
      </span>
      <br />
    </p>    
  </div>
</div>
</form>
<p class="pageback"><a class="pageback" href="<?php echo $themeObject->BackUrl(); ?>">&#171; <?php echo lang('back')?></a></p>
 
<?php
}
 
include_once("footer.php");
 
# vim:ts=4 sw=4 noet
?>