GetDb(); # first check if this association already exists $query = "SELECT * FROM ".cms_db_prefix(). "css_assoc WHERE assoc_css_id = ? AND assoc_type = ? AND assoc_to_id = ?"; $result = $db->Execute($query, array($id, $type, $template_id )); if ($result && $result->RecordCount() > 0) { $error = lang('associationexists'); $doadd = false; } # we get the name of the element (for logging) if ("template" == $type && $doadd) { $query = "SELECT css_name FROM ".cms_db_prefix()."css WHERE css_id = ?"; $result = $db->Execute($query, array($id)); if ($result && $result->RecordCount() > 0) { $line = $result->FetchRow(); $name = $line["css_name"]; } else { $doadd = false; $error = lang('invalidtemplate'); } } # get the next access_order $query = "SELECT max(assoc_order)+1 FROM ".cms_db_prefix()."css_assoc where assoc_to_id = ?"; $nextord = $db->GetOne($query,array($template_id)); if( !$nextord ) $nextord = 1; # everything is ok, we can insert the element. if ($doadd) { $time = $db->DBTimeStamp(time()); $query = "INSERT INTO ".cms_db_prefix()."css_assoc (assoc_to_id,assoc_css_id,assoc_type,create_date,modified_date,assoc_order) VALUES (?, ?, ?, ".$time.", ".$time.",?)"; $result = $db->Execute($query, array($template_id, $id, $type,$nextord)); if ($result) { // put mention into the admin log audit($id, 'Stylesheet Association: '.(isset($name)?$name:""), 'Added'); if ("template" == $type) { $time = $db->DBTimeStamp(time()); $tplquery = "UPDATE ".cms_db_prefix()."templates SET modified_date = ".$time." WHERE template_id = ?"; $tplresult = $db->Execute($tplquery, array($template_id)); } } else { $doadd = false; $error = lang('errorcreatingassociation'); } } # enf od adding query to db } # end of "if has access" # user does not have the right to create association else { $doadd = false; $error = lang('noaccessto', array(lang('addcss'))); } } # end if vars are set else { $doadd = false; $error = lang('informationmissing'); } #****************************************************************************** # end of treatment, we redirect #****************************************************************************** if ($doadd) { redirect("templatecss.php".$urlext."&id=$id&type=$type"); } else { redirect("templatecss.php".$urlext."&id=$id&type=$type&message=$error"); } # vim:ts=4 sw=4 noet ?>