[ Index ]
 

Code source de CMS made simple 1.0.5

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

title

Body

[fermer]

/admin/ -> editcss.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: editcss.php 3702 2007-01-02 05:21:25Z elijahlofgren $
  20  
  21  /**
  22   * This page is both the interface of the CSS editing, and used for actually
  23   * updating the CSS in the DB. The first part checks that all parameters are
  24   * valids, and then insert into the DB and redirect.
  25   *
  26   * The second part show the form to edit the CSS
  27   *
  28   * It takes one argument when called externally :
  29   * - $css_id : the id of the css to edit
  30   *
  31   * @since    0.6
  32   * @author    calexico
  33   */
  34  
  35  
  36  $CMS_ADMIN_PAGE=1;
  37  
  38  require_once ("../include.php");
  39  
  40  check_login();
  41  
  42  global $gCms;
  43  $styleops =& $gCms->GetStylesheetOperations();
  44  $db =& $gCms->GetDb();
  45  
  46  #******************************************************************************
  47  # Definition of global vars
  48  #******************************************************************************
  49  
  50  # this var is used to store any error that may occur
  51  $error = "";
  52  
  53  #******************************************************************************
  54  # we get the parameters
  55  #******************************************************************************
  56  
  57  # the new name of the css
  58  $css_name = "";
  59  if (isset($_POST["css_name"])) $css_name = $_POST["css_name"];
  60  
  61  $from = "";
  62  if (isset($_REQUEST["from"])) $from = $_REQUEST["from"];
  63  
  64  $templateid = "";
  65  if (isset($_REQUEST["templateid"])) $templateid = $_REQUEST["templateid"];
  66  
  67  # the old name of the css (if it has changed, we'll have to check that the new
  68  # one is not already used.&
  69  $orig_css_name = "";
  70  if (isset($_POST["orig_css_name"])) $orig_css_name = $_POST["orig_css_name"];
  71  
  72  # the content of the CSS
  73  $css_text = "";
  74  if (isset($_POST["css_text"])) $css_text = $_POST["css_text"];
  75  
  76  // Clean up name
  77  $css_name = htmlspecialchars($css_name, ENT_QUOTES);
  78  
  79  # the ID of the CSS
  80  $css_id = -1;
  81  if (isset($_POST["css_id"])) $css_id = $_POST["css_id"];
  82  else if (isset($_GET["css_id"])) $css_id = $_GET["css_id"];
  83  
  84  $media_type = array();
  85  if (isset($_POST['media_type'])) $media_type = $_POST['media_type'];
  86  
  87  # if the form has beeen cancelled, we redirect
  88  if (isset($_POST["cancel"]))
  89  {
  90      if ($from == 'templatecssassoc')
  91          redirect("listcssassoc.php?type=template&id=" . $templateid);
  92      else
  93          redirect("listcss.php");
  94      return;
  95  }
  96  
  97  #******************************************************************************
  98  # first, checking the user's permission
  99  #******************************************************************************
 100  $userid = get_userid();
 101  $access = check_permission($userid, 'Modify Stylesheets');
 102  
 103  if ($access)
 104  {
 105  
 106      # the user has submitted the form
 107      if (isset($_POST["editcss"]))
 108      {
 109          $validinfo = true;
 110  
 111          # check if the name is valid
 112          if ("" == $css_name)
 113          {
 114              $error .= "<li>".lang('nofieldgiven', array(lang('name')))."</li>";
 115              $validinfo = false;
 116          }
 117  
 118          # then check if new name is in use or not
 119          else if ($css_name != $orig_css_name)
 120          {
 121              $query = "SELECT css_id from ".cms_db_prefix()."css WHERE css_name = " . $db->qstr($css_name);
 122              $result = $db->Execute($query);
 123  
 124              if ($result && $result->RecordCount() > 0)
 125              {
 126                  $error .= "<li>".lang('cssalreadyused')."</li>";
 127                  $validinfo = false;
 128              }
 129          }
 130  
 131          # then check if css has content
 132          if ("" == $css_text)
 133          {
 134              $error .= "<li>".lang('nofieldgiven', array(lang('content')))."</li>";
 135              $validinfo = false;
 136          }
 137  
 138  #******************************************************************************
 139  # everything looks ok, we can update the CSS
 140  #******************************************************************************
 141          if ($validinfo)
 142          {
 143              //$query = "UPDATE ".cms_db_prefix()."css SET css_name = ?, css_text = ?, media_type = ?, modified_date = ? WHERE css_id = ?";
 144              //$result = $db->Execute($query,array($css_name, $css_text, $media_type, $db->DBTimeStamp(time()), $css_id));
 145              
 146              global $gCms;
 147              $styleops =& $gCms->GetStylesheetOperations();
 148              
 149              $onestylesheet = $styleops->LoadStylesheetByID($css_id);
 150              $onestylesheet->name = $css_name;
 151              $onestylesheet->value = $css_text;
 152  
 153                          #generate comma seperated list from media types
 154                          $types = "";
 155                          foreach ($media_type as $onetype) {
 156                            $types .= "$onetype, ";
 157                          }
 158                          if ($types!='') {
 159                          $types = substr($types, 0, -2); #strip last space and comma
 160                          } else {
 161                          $types='';
 162                          }
 163              $onestylesheet->media_type = $types;
 164              
 165              Events::SendEvent('Core', 'EditStylesheetPre', array('stylesheet' => &$onestylesheet));
 166              
 167              $result = $onestylesheet->Save();
 168  
 169              if ($result)
 170              {
 171                  #Start using new name, just in case this is an apply
 172                  $orig_css_name = $css_name;
 173                  
 174                  Events::SendEvent('Core', 'EditStylesheetPost', array('stylesheet' => &$onestylesheet));
 175  
 176                  audit($css_id, $css_name, 'Edited CSS');
 177  
 178                  # we now have to check which templates are associated with this CSS and update their modified date.
 179                  $cssquery = "SELECT assoc_to_id FROM ".cms_db_prefix()."css_assoc
 180                      WHERE    assoc_type        = 'template'
 181                      AND        assoc_css_id    =  ?";
 182                  $cssresult = $db->Execute($cssquery,array($css_id));
 183  
 184                  # now updating templates
 185                  while ($cssresult && $line = $cssresult->FetchRow())
 186                  {
 187                      $query = "UPDATE ".cms_db_prefix()."templates SET modified_date = ".$db->DBTimeStamp(time())." 
 188                          WHERE template_id = '".$line["assoc_to_id"]."'";
 189                      $result = $db->Execute($query);
 190  
 191                      if (FALSE == $result)
 192                      {
 193                          $error .= "<li>".lang('errorupdatingtemplate')."</li>";
 194                      }
 195                  }
 196                      
 197                  if (!isset($_POST["apply"]))
 198                  {
 199                      if ($from == 'templatecssassoc')
 200                          redirect("listcssassoc.php?type=template&id=" . $templateid);
 201                      else
 202                          redirect("listcss.php");
 203                      return;
 204                  }
 205              }
 206              else
 207              {
 208                  $error .= "<li>".lang('errorupdatingcss')."</li>";
 209              }
 210          } # end of updating
 211      } # end of the user has submitted
 212      
 213      # we've been called with a css id, we get it to show it on the form
 214      else if (-1 != $css_id)
 215      {
 216  
 217          # we get the CSS in the DB
 218          $query = "SELECT * from ".cms_db_prefix()."css WHERE css_id = ?"; 
 219          $result = $db->Execute($query,array($css_id));
 220  
 221          # we put the content in vars
 222          if ($result && $result->RecordCount() > 0)
 223          {
 224              $row = $result->FetchRow();
 225              $css_name        = $row["css_name"];
 226              $orig_css_name    = $row["css_name"];
 227              $css_text        = $row["css_text"];
 228              $media_type        = $row["media_type"];
 229          }
 230          else
 231          {
 232              $error .= "<li>".lang('errorretrievingcss')."</li>";
 233          }
 234      } # end of getting css
 235  } # end of has access
 236  
 237  if (strlen($css_name) > 0)
 238      {
 239      $CMS_ADMIN_SUBTITLE = $css_name;
 240      }
 241  if (isset($_POST["apply"]))
 242      {
 243          $CMS_EXCLUDE_FROM_RECENT=1;
 244      }
 245  
 246  include_once ("header.php");
 247  
 248  # if the user has no acess, we display an error
 249  if (!$access)
 250  {
 251      echo "<div class=\"pageerrorcontainer\"><p class=\"pageerror\">".lang('noaccessto', array(lang('editcss')))."</p></div>";
 252  }
 253  
 254  # else, we can display the form
 255  else
 256  {
 257      # first displaying erros if any
 258      if ($error != "")
 259      {
 260          echo "<div class=\"pageerrorcontainer\"><ul class=\"pageerror\">".$error."</ul></div>";
 261      }
 262  ?>
 263  
 264  <div class="pagecontainer">
 265      <?php echo $themeObject->ShowHeader('editstylesheet'); ?>
 266      <form method="post" action="editcss.php">
 267          <div class="pageoverflow">
 268              <p class="pagetext">&nbsp;</p>
 269              <p class="pageinput">
 270                  <input type="submit" value="<?php echo lang('submit')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 271                  <input type="submit" name="apply" value="<?php echo lang('apply')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 272                  <input type="submit" name="cancel" value="<?php echo lang('cancel')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 273              </p>
 274          </div>
 275          <div class="pageoverflow">
 276              <p class="pagetext"><?php echo lang('name')?>:</p>
 277              <p class="pageinput">
 278                  <input type="hidden" name="orig_css_name" value="<?php echo $orig_css_name?>" />
 279                  <input type="text" class="name" name="css_name" maxlength="255" value="<?php echo $css_name?>" />                
 280              </p>
 281          </div>
 282          <div class="pageoverflow">
 283              <p class="pagetext"><?php echo lang('content')?>:</p>
 284              <p class="pageinput"><textarea class="pagebigtextarea" name="css_text"><?php echo $css_text?></textarea></p>
 285          </div>
 286          <div class="pageoverflow">
 287              <p class="pagetext"><?php echo lang('mediatype')?>:</p>
 288              <p class="pageinput">
 289  <?php
 290  
 291  #open up the list to array
 292  
 293  
 294  if (!is_array($media_type)) {
 295    $media_type = split (", " , $media_type);
 296  }
 297  
 298  $existingtypes = array("all", 
 299                 "aural", 
 300                 "braille", 
 301                 "embossed", 
 302                 "handheld", 
 303                 "print", 
 304                 "projection", 
 305                 "screen", 
 306                 "tty", 
 307                 "tv"
 308                 );
 309  
 310      $types = "";
 311      $types .= "<fieldset style=\"width:60em;\">\n";
 312      $types .= "<legend>Media type</legend>\n\n";
 313      $i = 0;
 314      foreach ($existingtypes as $onetype)
 315        {
 316          $i++;
 317          $types .= '<input name="media_type['.$i.']" type="checkbox" value="'.$onetype.'"';
 318  
 319          if (is_array($media_type)) {
 320            if (in_array($onetype, $media_type) )
 321          {
 322            $types .= ' checked="checked" ';
 323          }
 324          }
 325          $types .= " />\n\n";
 326          $types .= '<label for="media_type">'. lang("mediatype_".$onetype) .'</label><br />'."\n";
 327        }
 328      $types .= "</fieldset>";
 329  
 330      echo $types;
 331  ?>
 332  
 333  
 334              </p>
 335          </div>
 336          <div class="pageoverflow">
 337              <p class="pagetext">&nbsp;</p>
 338              <p class="pageinput">
 339                  <input type="hidden" name="css_id" value="<?php echo $css_id?>" />
 340                  <input type="hidden" name="from" value="<?php echo $from?>" />
 341                  <input type="hidden" name="templateid" value="<?php echo $templateid?>" />
 342                  <input type="hidden" name="editcss" value="true" />
 343                  <input type="submit" value="<?php echo lang('submit')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 344                  <input type="submit" name="apply" value="<?php echo lang('apply')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 345                  <input type="submit" name="cancel" value="<?php echo lang('cancel')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 346              </p>
 347          </div>
 348      </form>
 349  </div>
 350  
 351  <?php
 352  
 353  } # end of displaying form
 354  
 355  echo '<p class="pageback"><a class="pageback" href="'.$themeObject->BackUrl().'">&#171; '.lang('back').'</a></p>';
 356  
 357  include_once ("footer.php");
 358  
 359  # vim:ts=4 sw=4 noet
 360  ?>


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