GetStylesheetOperations(); $db = $gCms->GetDb(); $dateformat = trim(get_preference(get_userid(),'date_format_string','%x %X')); if( empty($dateformat) ) { $dateformat = '%x %X'; } #****************************************************************************** # Definition of global vars #****************************************************************************** # this var is used to store any error that may occur $error = ""; #****************************************************************************** # we get the parameters #****************************************************************************** # the new name of the css $css_name = ""; if (isset($_POST["css_name"])) $css_name = $_POST["css_name"]; $from = ""; if (isset($_REQUEST["from"])) $from = $_REQUEST["from"]; $templateid = ""; if (isset($_REQUEST["templateid"])) $templateid = (int)$_REQUEST["templateid"]; # the old name of the css (if it has changed, we'll have to check that the new # one is not already used.& $orig_css_name = ""; if (isset($_POST["orig_css_name"])) $orig_css_name = $_POST["orig_css_name"]; # the content of the CSS $css_text = ""; if (isset($_POST["css_text"])) $css_text = $_POST["css_text"]; // Clean up name $css_name = htmlspecialchars($css_name, ENT_QUOTES); # the ID of the CSS $css_id = -1; if (isset($_POST["css_id"])) $css_id = $_POST["css_id"]; else if (isset($_GET["css_id"])) $css_id = $_GET["css_id"]; $media_type = array(); if (isset($_POST['media_type'])) $media_type = $_POST['media_type']; $media_query = ''; if (isset($_POST['media_query'])) $media_query = $_POST['media_query']; $ajax = false; if (isset($_POST['ajax']) && $_POST['ajax']) $ajax = true; # if the form has beeen cancelled, we redirect if (isset($_POST["cancel"])) { if ($from == 'templatecssassoc') redirect("listcssassoc.php".$urlext."&type=template&id=" . $templateid); else redirect("listcss.php".$urlext); return; } #****************************************************************************** # first, checking the user's permission #****************************************************************************** $userid = get_userid(); $access = check_permission($userid, 'Modify Stylesheets'); if ($access) { # the user has submitted the form if (isset($_POST["editcss"])) { $validinfo = true; # check if the name is valid if ("" == $css_name) { $error .= "
  • ".lang('nofieldgiven', array(lang('name')))."
  • "; $validinfo = false; } # then check if new name is in use or not else if ($styleops->CheckExistingStylesheetName($css_name, $css_id)) { $error .= "
  • ".lang('cssalreadyused')."
  • "; $validinfo = false; } # then check if css has content if ("" == $css_text) { $error .= "
  • ".lang('nofieldgiven', array(lang('content')))."
  • "; $validinfo = false; } $styleops = cmsms()->GetStylesheetOperations(); $onestylesheet = $styleops->LoadStylesheetByID($css_id); if( !is_object($onestylesheet) ) { $error .= '
  • '.lang('stylesheetnotfound',$css_id).'
  • '; $validinfo = FALSE; } // ****************************************************************************** // everything looks ok, we can update the CSS // ****************************************************************************** //$query = "UPDATE ".cms_db_prefix()."css SET css_name = ?, css_text = ?, media_type = ?, modified_date = ? WHERE css_id = ?"; //$result = $db->Execute($query,array($css_name, $css_text, $media_type, $db->DBTimeStamp(time()), $css_id)); if ($validinfo) { $onestylesheet->name = $css_name; $onestylesheet->value = $css_text; #generate comma seperated list from media types $types = ""; foreach ($media_type as $onetype) { $types .= "$onetype, "; } if ($types!='') { $types = substr($types, 0, -2); #strip last space and comma } else { $types=''; } $onestylesheet->media_type = $types; $onestylesheet->media_query = $media_query; Events::SendEvent('Core', 'EditStylesheetPre', array('stylesheet' => &$onestylesheet)); $result = $onestylesheet->Save(); // Update the css hash // deprecated: this was used by the stylesheet.php function which we no longer distribute // as of CMSMS 1.10. $config = $gCms->GetConfig(); $hashfile = cms_join_path($config['root_path'],'tmp','cache','csshash.dat'); $md5sum = md5($css_text); $csshash = csscache_csvfile_to_hash($hashfile); $csshash[$css_id] = $md5sum; csscache_hash_to_csvfile($hashfile,$csshash); if ($result) { #Start using new name, just in case this is an apply $orig_css_name = $css_name; Events::SendEvent('Core', 'EditStylesheetPost', array('stylesheet' => &$onestylesheet)); // put mention into the admin log audit($css_id, 'Stylesheet: '.$css_name, 'Changed'); # we now have to check which templates are associated with this CSS and update their modified date. $cssquery = "SELECT assoc_to_id FROM ".cms_db_prefix()."css_assoc WHERE assoc_type = 'template' AND assoc_css_id = ?"; $cssresult = $db->Execute($cssquery,array($css_id)); # now updating templates while ($cssresult && $line = $cssresult->FetchRow()) { $query = "UPDATE ".cms_db_prefix()."templates SET modified_date = ".$db->DBTimeStamp(time())." WHERE template_id = '".$line["assoc_to_id"]."'"; $result = $db->Execute($query); if (FALSE == $result) { $error .= "
  • ".lang('errorupdatingtemplate')."
  • "; } } if (!isset($_POST["apply"])) { if ($from == 'templatecssassoc') redirect("listcssassoc.php".$urlext."&type=template&id=" . $templateid); else redirect("listcss.php".$urlext); return; } } else { $error .= "
  • ".lang('errorupdatingcss')."
  • "; } } # end of updating } # end of the user has submitted if ($ajax) { header('Content-Type: text/xml'); print ''; print ''; if ($error) { print 'Error'; print '
    '; } else { print 'Success'; print '
    '; } print '
    '; exit; } # we've been called with a css id, we get it to show it on the form else if (-1 != $css_id) { # we get the CSS in the DB $query = "SELECT * from ".cms_db_prefix()."css WHERE css_id = ?"; $result = $db->Execute($query,array($css_id)); # we put the content in vars if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); $css_name = $row["css_name"]; $orig_css_name = $row["css_name"]; $css_text = $row["css_text"]; $media_type = $row["media_type"]; $media_query = $row["media_query"]; $lastmodified = $row["modified_date"]; } else { $error .= "
  • ".lang('errorretrievingcss')."
  • "; } } # end of getting css } # end of has access if (strlen($css_name) > 0) { $CMS_ADMIN_SUBTITLE = $css_name; } if (isset($_POST["apply"])) { $CMS_EXCLUDE_FROM_RECENT=1; } $addlScriptSubmit = ''; $syntaxmodule = get_preference(get_userid(FALSE),'syntaxhighlighter'); if( $syntaxmodule && ($module = ModuleOperations::get_instance()->get_module_instance($syntaxmodule)) ) { if( $module->IsSyntaxHighlighter() && $module->SyntaxActive() ) { $addlScriptSubmit .= $module->SyntaxPageFormSubmit(); } } $closestr = cms_html_entity_decode(lang('close')); $headtext = << //

    ' + e.details + '<\/p><\/div>'; $('[name=cancel]').fadeOut(); $('[name=cancel]').attr('value','{$closestr}'); $('[name=cancel]').fadeIn(); } else { htmlShow = '