[ Index ]
 

Code source de CMS made simple 1.0.5

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

title

Body

[fermer]

/admin/ -> addcssassoc.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: addcssassoc.php 3601 2006-12-20 21:04:54Z calguy1000 $
  20  
  21  /**
  22   * The goal of this page is to create a CSS association. So firts, what is a css
  23   * association, and how it works.
  24   *
  25   * The idea came that CSS should be broken in small pieces, easily maintanable,
  26   * instead of one big CSS. So, the user created several little CSS pieces :
  27   * - css_menu
  28   * - css_header
  29   * - css_footer
  30   * - css_whatever
  31   *
  32   * There is a table (css_assoc) on the DB with the following fields :
  33   * - assoc_to_id    : the id of the element we associate the CSS with
  34   *                      it can be a template id, a page id, a what you want id
  35   * - assoc_css_id    : the id of the CSS we link
  36   * - assoc_type        : what do we link the CSS to ? for the moment, only template
  37   * - create_date    : the create date of this association
  38   * - modified_date    : the modified date of this association (which is not used
  39   *                      at the moment.
  40   *
  41   * This page takes arguments as GET variables. 3 arguments are necessary :
  42   * - $id        : refers to "assoc_to_id", the id of the element
  43   * - $css_id    : the id of the CSS we link, refers to "assoc_css_id"
  44   * - $type        : the type of element $id refers to (only template for the
  45   *                  moment)
  46   *
  47   * @since    0.6
  48   * @author    calexico
  49   */
  50  
  51      
  52  $CMS_ADMIN_PAGE=1;
  53  
  54  require_once ("../include.php");
  55  
  56  check_login();
  57  
  58  #******************************************************************************
  59  # global variables definition
  60  #******************************************************************************
  61  
  62  # variable to check if we'll make the association or not
  63  # will be set to false if an error is encountered
  64  $doadd = true;
  65  
  66  #******************************************************************************
  67  # start of the treatment
  68  #******************************************************************************
  69  if (isset($_POST["css_id"]) && isset($_POST["id"]) && isset($_POST["type"]))
  70  {
  71  
  72      # we get the arguments as local vars (easier)
  73      $css_id = $_POST["css_id"];
  74      $id        = $_POST["id"];
  75      $type    = $_POST["type"];
  76  
  77      # we then check permissions
  78      $userid = get_userid();
  79      $access = check_permission($userid, 'Add Stylesheet Assoc');
  80  
  81  #******************************************************************************
  82  # the user has permissions, and vars are set, we can go on
  83  #******************************************************************************
  84      if ($access)
  85      {
  86  
  87        global $gCms;
  88        $db =& $gCms->GetDb();
  89  
  90          # first check if this association already exists
  91          $query = "SELECT * FROM ".cms_db_prefix()."css_assoc WHERE assoc_to_id = ? AND assoc_type = ? AND assoc_css_id = ?";
  92          $result = $db->Execute($query, array($id, $type, $css_id));
  93  
  94          if ($result && $result->RecordCount() > 0)
  95          {
  96              $error = lang('associationexists');
  97              $doadd = false;
  98          }
  99  
 100          # we get the name of the element (for logging)
 101          if ("template" == $type && $doadd)
 102          {
 103              $query = "SELECT template_name FROM ".cms_db_prefix()."templates WHERE template_id = ?";
 104              $result = $db->Execute($query, array($id));
 105              
 106              if ($result && $result->RecordCount() > 0)
 107              {
 108                  $line = $result->FetchRow();
 109                  $name = $line["template_name"];
 110              }
 111              else
 112              {
 113                  $doadd = false;
 114                  $error = lang('invalidtemplate');
 115              }
 116          }
 117  
 118          # everything is ok, we can insert the element.
 119          if ($doadd)
 120          {
 121              $time = $db->DBTimeStamp(time());
 122              $query = "INSERT INTO ".cms_db_prefix().
 123                  "css_assoc (assoc_to_id,assoc_css_id,assoc_type,create_date,modified_date)" .
 124                  " VALUES (?,?,?,".$time.",".$time.")";
 125              $result = $db->Execute($query, array($id,$css_id,$type));
 126  
 127              if ($result)
 128              {
 129                  audit($id, (isset($name)?$name:""), 'Added Stylesheet Association');
 130  
 131                  if ("template" == $type)
 132                  {
 133                      $time = $db->DBTimeStamp(time());
 134                      $tplquery = "UPDATE ".cms_db_prefix().
 135                      "templates SET modified_date = ".$time."  WHERE template_id = ?";
 136                      $tplresult = $db->Execute($tplquery, array($id));
 137                  }
 138              }
 139              else
 140              {
 141                  $doadd = false;
 142                  $error = lang('errorcreatingassociation');
 143              }
 144          } # enf od adding query to db
 145      } # end of "if has access"
 146      
 147      # user does not have the right to create association
 148      else
 149      {
 150          $doadd = false;
 151          $error = lang('noaccessto', array(lang('addcss')));
 152      }
 153  } # end if vars are set
 154  else
 155  {
 156      $doadd = false;
 157      $error = lang('informationmissing');
 158  }
 159  
 160  #******************************************************************************
 161  # end of treatment, we redirect
 162  #******************************************************************************
 163  if ($doadd)
 164  {
 165      redirect("listcssassoc.php?id=$id&type=$type");
 166  }
 167  else
 168  {
 169      redirect("listcssassoc.php?id=$id&type=$type&message=$error");
 170  }
 171  
 172  # vim:ts=4 sw=4 noet
 173  ?>


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