[ Index ] |
|
Code source de CMS made simple 1.0.5 |
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: addtemplateassoc.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["template_id"]) && isset($_POST["id"]) && isset($_POST["type"])) 70 { 71 72 # we get the arguments as local vars (easier) 73 $template_id = $_POST["template_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 global $gCms; $db =& $gCms->GetDb(); 87 88 # first check if this association already exists 89 $query = "SELECT * FROM ".cms_db_prefix(). 90 "css_assoc WHERE assoc_css_id = ? AND assoc_type = ? AND assoc_to_id = ?"; 91 $result = $db->Execute($query, array($id, $type, $template_id )); 92 93 if ($result && $result->RecordCount() > 0) 94 { 95 $error = lang('associationexists'); 96 $doadd = false; 97 } 98 99 # we get the name of the element (for logging) 100 if ("template" == $type && $doadd) 101 { 102 $query = "SELECT css_name FROM ".cms_db_prefix()."css WHERE css_id = ?"; 103 $result = $db->Execute($query, array($id)); 104 105 if ($result && $result->RecordCount() > 0) 106 { 107 $line = $result->FetchRow(); 108 $name = $line["css_name"]; 109 } 110 else 111 { 112 $doadd = false; 113 $error = lang('invalidtemplate'); 114 } 115 } 116 117 # everything is ok, we can insert the element. 118 if ($doadd) 119 { 120 $time = $db->DBTimeStamp(time()); 121 $query = "INSERT INTO ".cms_db_prefix()."css_assoc (assoc_to_id,assoc_css_id,assoc_type,create_date,modified_date) VALUES (?, ?, ?, ".$time.", ".$time.")"; 122 $result = $db->Execute($query, array($template_id, $id, $type)); 123 124 if ($result) 125 { 126 audit($id, (isset($name)?$name:""), 'Added Stylesheet Association'); 127 128 if ("template" == $type) 129 { 130 $time = $db->DBTimeStamp(time()); 131 $tplquery = "UPDATE ".cms_db_prefix()."templates SET modified_date = ".$time." WHERE template_id = ?"; 132 $tplresult = $db->Execute($tplquery, array($template_id)); 133 } 134 } 135 else 136 { 137 $doadd = false; 138 $error = lang('errorcreatingassociation'); 139 } 140 } # enf od adding query to db 141 } # end of "if has access" 142 143 # user does not have the right to create association 144 else 145 { 146 $doadd = false; 147 $error = lang('noaccessto', array(lang('addcss'))); 148 } 149 } # end if vars are set 150 else 151 { 152 $doadd = false; 153 $error = lang('informationmissing'); 154 } 155 156 #****************************************************************************** 157 # end of treatment, we redirect 158 #****************************************************************************** 159 if ($doadd) 160 { 161 redirect("templatecss.php?id=$id&type=$type"); 162 } 163 else 164 { 165 redirect("templatecss.php?id=$id&type=$type&message=$error"); 166 } 167 168 # vim:ts=4 sw=4 noet 169 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |