| [ 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: addcss.php 3700 2007-01-02 04:44:30Z elijahlofgren $ 20 21 /** 22 * This page is responsible for showing the interface to add a new CSS. There is 23 * a form that returns back to this page. The content of the form is then 24 * checked to verify that all parameters are valid. 25 * 26 * - If all parameter are valid, the result is stored in the DB 27 * - If one or more parameters are not valid, the form is redisplayed. An error 28 * message indictaes to the user what went wrong. 29 * 30 * There is no GET parameters. 31 * 32 * @since 0.6 33 * @author calexico 34 */ 35 36 37 $CMS_ADMIN_PAGE=1; 38 39 require_once ("../include.php"); 40 41 check_login(); 42 43 global $gCms; 44 $styleops =& $gCms->GetStylesheetOperations(); 45 $db =& $gCms->GetDb(); 46 47 #****************************************************************************** 48 # global variables definitions 49 #****************************************************************************** 50 51 # this variable is used to store an eventual error message. 52 $error = ""; 53 54 #****************************************************************************** 55 # we get the content of the form if there are not empty. 56 #****************************************************************************** 57 58 # first ; the content of the css 59 $css_text = ""; 60 if (isset($_POST["css_text"])) $css_text = $_POST["css_text"]; 61 62 # then its name 63 $css_name = ""; 64 if (isset($_POST["css_name"])) $css_name = $_POST["css_name"]; 65 66 // Now clean up name 67 $css_name = htmlspecialchars($css_name, ENT_QUOTES); 68 69 $media_type = array(); 70 if (isset($_POST['media_type'])) $media_type = $_POST['media_type']; 71 72 #****************************************************************************** 73 # if the form was cancelled, we get back to the CSS list 74 #****************************************************************************** 75 if (isset($_POST["cancel"])) 76 { 77 redirect("listcss.php"); 78 return; 79 } 80 81 #****************************************************************************** 82 # we now check that user has access to add CSS 83 #****************************************************************************** 84 $userid = get_userid(); 85 $access = check_permission($userid, 'Add Stylesheets'); 86 87 if ($access) 88 { 89 90 #****************************************************************************** 91 # if the var "addcss" is set, this means that the form has been submitted. 92 # we check if params are valid 93 #****************************************************************************** 94 if (isset($_POST["addcss"])) 95 { 96 # used to check if we will save the form or not 97 $validinfo = true; 98 99 # if no CSS name was given 100 if ("" == $css_name) 101 { 102 $error .= "<li>".lang('nofieldgiven', array(lang('name')))."</li>"; 103 $validinfo = false; 104 105 } 106 # the CSS has a name, we check if it already exists or not 107 else 108 { 109 $query = "SELECT css_id from ".cms_db_prefix()."css WHERE css_name = " . $db->qstr($css_name); 110 $result = $db->Execute($query); 111 112 if ($result && $result->RecordCount() > 0) 113 { 114 $error .= "<li>".lang('cssalreadyused')."</li>"; 115 $validinfo = false; 116 } 117 } 118 119 # now checking the content of the CSS 120 if ("" == $css_text) 121 { 122 $error .= "<li>".lang('nofieldgiven', array(lang('content')))."</li>"; 123 $validinfo = false; 124 } 125 126 #****************************************************************************** 127 # everythings seems to be ok, we can try to save the form 128 #****************************************************************************** 129 if ($validinfo) 130 { 131 $newstylesheet = new Stylesheet(); 132 $newstylesheet->name = $css_name; 133 $newstylesheet->value = $css_text; 134 $types = ""; 135 136 #generate comma separated list 137 foreach ($media_type as $onetype) { 138 $types .= "$onetype, "; 139 } 140 if ($types!='') { 141 $types = substr($types, 0, -2); #strip last space and comma 142 } else { 143 $types=''; 144 } 145 146 $newstylesheet->media_type = $types; 147 148 Events::SendEvent('Core', 'AddStylesheetPre', array('stylesheet' => &$newstylesheet)); 149 150 $result = $newstylesheet->Save(); 151 152 # we now have to check that everything went well 153 if ($result) 154 { 155 #Sent the post event 156 Events::SendEvent('Core', 'AddStylesheetPost', array('stylesheet' => &$newstylesheet)); 157 158 # it's ok, we record the operation in the admin log 159 audit($newstylesheet->id, $css_name, 'Added CSS'); 160 161 # and goes back to the css list 162 redirect("listcss.php"); 163 return; 164 } 165 else 166 { 167 $error .= "<li>".lang('errorinsertingcss')."</li>"; 168 } 169 } 170 } 171 } 172 173 include_once ("header.php"); 174 175 #****************************************************************************** 176 # the user does not have access : error message 177 #****************************************************************************** 178 if (!$access) 179 { 180 echo "<div class=\"pageerrorcontainer\"><p class=\"pageerror\">".lang('noaccessto', array(lang('addstylesheet')))."</p></div>"; 181 } 182 #****************************************************************************** 183 # the user has access, we display the form 184 #****************************************************************************** 185 else 186 { 187 188 # the user has correct rights, we display error message if any 189 if ("" != $error) 190 { 191 echo "<div class=\"pageerrorcontainer\"><ul class=\"pageerror\">".$error."</ul></div>"; 192 } 193 194 #****************************************************************************** 195 # we now display the content of the form, in HTML 196 #****************************************************************************** 197 ?> 198 199 200 <div class="pagecontainer"> 201 <?php echo $themeObject->ShowHeader('addstylesheet'); ?> 202 <form method="post" action="addcss.php"> 203 <div class="pageoverflow"> 204 <p class="pagetext"><?php echo lang('name')?>:</p> 205 <p class="pageinput"><input type="text" class="name" name="css_name" maxlength="255" value="<?php echo $css_name?>" /></p> 206 </div> 207 <div class="pageoverflow"> 208 <p class="pagetext"><?php echo lang('content')?>:</p> 209 <p class="pageinput"><textarea class="pagebigtextarea" name="css_text" cols="" rows=""><?php echo $css_text?></textarea></p> 210 </div> 211 <div class="pageoverflow"> 212 <p class="pagetext"><?php echo lang('mediatype')?>:</p> 213 <p class="pageinput"> 214 <?php 215 $existingtypes = array("all", 216 "aural", 217 "braille", 218 "embossed", 219 "handheld", 220 "print", 221 "projection", 222 "screen", 223 "tty", 224 "tv" 225 ); 226 227 $types = ""; 228 $types .= "<fieldset style=\"width:60em;\">\n"; 229 $types .= "<legend>Media type</legend>\n"; 230 $i = 0; 231 foreach ($existingtypes as $onetype) 232 { 233 $i++; 234 $types .= '<input name="media_type['.$i.']" type="checkbox" value="'.$onetype.'"'; 235 236 if (is_array($media_type)) { 237 if (in_array($onetype, $media_type) ) 238 { 239 $types .= ' checked="checked" '; 240 } 241 } 242 $types .= " />\n\n"; 243 $types .= '<label for="media_type['.$i.']">'. lang("mediatype_".$onetype) ."</label>\n<br />"; 244 245 } 246 $types .= "</fieldset>"; 247 248 echo $types; 249 ?> 250 251 252 </p> 253 </div> 254 <div class="pageoverflow"> 255 <p class="pagetext"> </p> 256 <p class="pageinput"> 257 <input type="hidden" name="addcss" value="true" /> 258 <input type="submit" value="<?php echo lang('submit')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" /> 259 <input type="submit" name="cancel" value="<?php echo lang('cancel')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" /> 260 </p> 261 </div> 262 </form> 263 </div> 264 265 <?php 266 echo '<p class="pageback"><a class="pageback" href="'.$themeObject->BackUrl().'">« '.lang('back').'</a></p>'; 267 } # end of displaying the form 268 include_once ("footer.php"); 269 270 # vim:ts=4 sw=4 noet 271 ?>
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 |