[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/ -> addtemplate.php (source)

   1  <?php
   2  #CMS - CMS Made Simple
   3  #(c)2004 by Ted Kulp (wishy@users.sf.net)
   4  #This project's homepage is: http://cmsmadesimple.sf.net
   5  #
   6  #This program is free software; you can redistribute it and/or modify
   7  #it under the terms of the GNU General Public License as published by
   8  #the Free Software Foundation; either version 2 of the License, or
   9  #(at your option) any later version.
  10  #
  11  #This program is distributed in the hope that it will be useful,
  12  #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  #GNU General Public License for more details.
  15  #You should have received a copy of the GNU General Public License
  16  #along with this program; if not, write to the Free Software
  17  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18  #
  19  #$Id: addtemplate.php 3601 2006-12-20 21:04:54Z calguy1000 $
  20  
  21  $CMS_ADMIN_PAGE=1;
  22  
  23  require_once ("../include.php");
  24  require_once ("../lib/classes/class.template.inc.php");
  25  
  26  check_login();
  27  
  28  $dflt_content='
  29  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  30  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
  31  <head>
  32  <title>{sitename} - {title}</title>
  33  {metadata}
  34  {stylesheet}
  35  </head>
  36  <body>
  37  
  38  <!-- start header -->
  39  <div id="header">
  40    <h1>{sitename}</h1>
  41  </div>
  42  <!-- end header -->
  43  
  44  <!-- start menu -->
  45  <div id="menu">
  46    {menu}
  47  </div>
  48  <!-- end menu -->
  49  
  50  <!-- start content -->
  51  <div id="content">
  52    <h1>{title}</h1>
  53    {content}
  54  </div>
  55  <!-- end content -->
  56  
  57  </body>
  58  </html>
  59  ';
  60  
  61  $error = "";
  62  
  63  $template = "";
  64  if (isset($_POST["template"])) $template = $_POST["template"];
  65  
  66  $content = $dflt_content;
  67  if (isset($_POST["content"])) $content = $_POST["content"];
  68  
  69  $stylesheet = "";
  70  if (isset($_POST["stylesheet"])) $stylesheet = $_POST["stylesheet"];
  71  
  72  $encoding = "";
  73  if (isset($_POST["encoding"])) $encoding = $_POST["encoding"];
  74  
  75  $preview = false;
  76  if (isset($_POST["preview"])) $preview = true;
  77  
  78  $active = 1;
  79  if (!isset($_POST["active"]) && isset($_POST["addsection"])) $active = 0;
  80  
  81  if (isset($_POST["cancel"]))
  82  {
  83      redirect("listtemplates.php");
  84      return;
  85  }
  86  
  87  global $gCms;
  88  $db =& $gCms->GetDb();
  89  $templateops =& $gCms->GetTemplateOperations();
  90  
  91  $userid = get_userid();
  92  $access = check_permission($userid, 'Add Templates');
  93  
  94  $use_javasyntax = false;
  95  if (get_preference($userid, 'use_javasyntax') == "1") $use_javasyntax = true;
  96  
  97  if ($access)
  98  {
  99      if (isset($_POST["addtemplate"]) && !$preview)
 100      {
 101          $validinfo = true;
 102  
 103          if ($template == "")
 104          {
 105              $error .= "<li>".lang("nofieldgiven",array(lang('name')))."</li>";
 106              $validinfo = false;
 107          }
 108          else
 109          {
 110              $query = "SELECT template_id from ".cms_db_prefix()."templates WHERE template_name = " . $db->qstr($template);
 111              $result = $db->Execute($query);
 112  
 113              if ($result && $result->RecordCount() > 0)
 114              {
 115                  $error .= "<li>".lang('templateexists')."</li>";
 116                  $validinfo = false;
 117              }
 118          }
 119  
 120          if ($content == "")
 121          {
 122              $error .= "<li>".lang('nofieldgiven', array(lang('content')))."</li>";
 123              $validinfo = false;
 124          }
 125  
 126          if ($validinfo)
 127          {
 128              $newtemplate = new Template();
 129              $newtemplate->name = $template;
 130              $newtemplate->content = $content;
 131              $newtemplate->stylesheet = $stylesheet;
 132              $newtemplate->encoding = $encoding;
 133              $newtemplate->active = $active;
 134              $newtemplate->default = 0;
 135  
 136              #Perform the addtemplate_pre callback
 137              foreach($gCms->modules as $key=>$value)
 138              {
 139                  if ($gCms->modules[$key]['installed'] == true &&
 140                      $gCms->modules[$key]['active'] == true)
 141                  {
 142                      $gCms->modules[$key]['object']->AddTemplatePre($newtemplate);
 143                  }
 144              }
 145              
 146              Events::SendEvent('Core', 'AddTemplatePre', array('template' => &$newtemplate));
 147  
 148              $result = $newtemplate->save();
 149  
 150              if ($result)
 151              {
 152                  #Perform the addtemplate_post callback
 153                  foreach($gCms->modules as $key=>$value)
 154                  {
 155                      if ($gCms->modules[$key]['installed'] == true &&
 156                          $gCms->modules[$key]['active'] == true)
 157                      {
 158                          $gCms->modules[$key]['object']->AddTemplatePost($newtemplate);
 159                      }
 160                  }
 161                  
 162                  Events::SendEvent('Core', 'AddTemplatePost', array('template' => &$newtemplate));
 163  
 164                  audit($newtemplate->id, $template, 'Added Template');
 165                  redirect("listtemplates.php");
 166                  return;
 167              }
 168              else
 169              {
 170                  $error .= "<li>".lang('errorinsertingtemplate')."$query</li>";
 171              }
 172          }
 173      }
 174  }
 175  
 176  include_once ("header.php");
 177  
 178  if (!$access)
 179  {
 180      echo "<div class=\"pageerrorcontainer\"><p class=\"pageerror\">".lang('noaccessto', array(lang('addtemplate')))."</p></div>";
 181  }
 182  else
 183  {
 184      if ($error != "")
 185      {
 186          echo "<div class=\"pageerrorcontainer\"><ul class=\"pageerror\">".$error."</ul></div>";
 187      }
 188  
 189      if ($preview)
 190      {
 191          $data["title"] = "TITLE HERE";
 192          $data["content"] = "Test Content";
 193          #$data["template_id"] = $template_id;
 194          $data["stylesheet"] = $stylesheet;
 195          $data["template"] = $content;
 196          $data["encoding"] = $encoding;
 197  
 198          $tmpfname = '';
 199          if (is_writable($config["previews_path"]))
 200          {
 201              $tmpfname = tempnam($config["previews_path"], "cmspreview");
 202          }
 203          else
 204          {
 205              $tmpfname = tempnam(TMP_CACHE_LOCATION, "cmspreview");
 206          }
 207          $handle = fopen($tmpfname, "w");
 208          fwrite($handle, serialize($data));
 209          fclose($handle);
 210  
 211  ?>
 212  <div class="pagecontainer">
 213      <p class="pageheader"><?php echo lang('preview')?></p>
 214      <iframe class="preview" name="preview" src="<?php echo $config["root_url"]?>/preview.php?tmpfile=<?php echo urlencode(basename($tmpfname))?>"></iframe>
 215  </div>
 216  <?php
 217  
 218      }
 219  ?>
 220  
 221  <div class="pagecontainer">
 222      <?php echo $themeObject->ShowHeader('addtemplate'); ?>
 223      <form method="post" action="addtemplate.php">
 224          <div class="pageoverflow">
 225              <p class="pagetext">*<?php echo lang('name')?>:</p>
 226              <p class="pageinput"><input class="name" type="text" name="template" maxlength="255" value="<?php echo $template?>" /></p>
 227          </div>
 228          <div class="pageoverflow">
 229              <p class="pagetext">*<?php echo lang('content')?>:</p>
 230              <p class="pageinput"><?php echo create_textarea(false, $content, 'content', 'pagebigtextarea', '', $encoding)?></p>
 231          </div>
 232          <?php if ($templateops->StylesheetsUsed() > 0) { ?>
 233          <div class="pageoverflow">
 234              <p class="pagetext"><?php echo lang('stylesheet')?>:</p>
 235              <p class="pageinput"><?php echo create_textarea(false, $stylesheet, 'stylesheet', 'pagebigtextarea', '', $encoding)?></p>
 236          </div>
 237          <?php } ?>
 238          <div class="pageoverflow">
 239              <p class="pagetext"><?php echo lang('encoding')?>:</p>
 240              <p class="pageinput"><?php echo create_encoding_dropdown('encoding', $encoding) ?></p>
 241          </div>
 242          <div class="pageoverflow">
 243              <p class="pagetext"><?php echo lang('active')?>:</p>
 244              <p class="pageinput"><input class="pagecheckbox" type="checkbox" name="active" <?php echo ($active == 1?"checked=\"checked\"":"")?> /></p>
 245          </div>
 246          <div class="pageoverflow">
 247              <p class="pagetext">&nbsp;</p>
 248              <p class="pageinput">
 249                  <input type="hidden" name="addtemplate" value="true"/>
 250                  <!--<input type="submit" name="preview" value="<?php echo lang('preview')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />-->
 251                  <input type="submit" name="submit" value="<?php echo lang('submit')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 252                  <input type="submit" name="cancel" value="<?php echo lang('cancel')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 253              </p>
 254          </div>
 255      </form>
 256  </div>
 257  
 258  <?php
 259  }
 260  echo '<p class="pageback"><a class="pageback" href="'.$themeObject->BackUrl().'">&#171; '.lang('back').'</a></p>';
 261  include_once ("footer.php");
 262  
 263  # vim:ts=4 sw=4 noet
 264  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7