GetDb(); #****************************************************************************** # global vars definition #****************************************************************************** # this var is used to store any error that may occur. $error = ""; # this one is used later to store all the css found, because they won't appear in the dropdown $csslist = array(); $type = ""; $name = ''; #****************************************************************************** # we now get the parameters #****************************************************************************** # getting variables if (isset($_REQUEST["type"])) $type = trim($_REQUEST["type"]) ; else $error = lang('typenotvalid'); if (isset($_REQUEST["id"])) $id = (int)$_REQUEST["id"] ; else $error = lang('idnotvalid'); if( isset($_REQUEST['cssid'])) $cssid = (int)$_REQUEST['cssid']; # if type is template, we get the name if (isset($type) && "template" == $type) { $query = "SELECT template_name FROM ".cms_db_prefix()."templates WHERE template_id = ?"; $result = $db->Execute($query, array($id)); if ($result) { $line = $result->FetchRow(); $name = $line['template_name']; } else { $error = lang('errorretrievingtemplate'); } } #****************************************************************************** # first getting all user permissions #****************************************************************************** $userid = get_userid(); $modify = check_permission($userid, 'Modify Stylesheet Assoc'); $delasso = check_permission($userid, 'Remove Stylesheet Assoc'); $addasso = check_permission($userid, 'Add Stylesheet Assoc'); #****************************************************************************** # Handle moving of entries #****************************************************************************** if( isset($_REQUEST['dir']) && $modify ) { switch(trim($_REQUEST['dir'])) { case 'up': { // get the ord id for this item $q1 = 'SELECT assoc_order FROM '.cms_db_prefix().'css_assoc WHERE assoc_to_id = ? AND assoc_css_id = ?'; $ord = $db->GetOne($q1,array($id,$cssid)); if( $ord > 0 ) { // get the item with the prev ord id $q2 = 'SELECT assoc_css_id FROM '.cms_db_prefix().'css_assoc WHERE assoc_to_id = ? AND assoc_order = ?'; $other_css = $db->GetOne($q2,array($id,$ord-1)); if( $other_css ) { // swap em $q3 = 'UPDATE '.cms_db_prefix().'css_assoc SET assoc_order = ? WHERE assoc_to_id = ? AND assoc_css_id = ?'; $db->Execute($q3,array($ord,$id,$other_css)); $db->Execute($q3,array($ord-1,$id,$cssid)); } } } break; case 'down': { // get the ord id for this item $q1 = 'SELECT assoc_order FROM '.cms_db_prefix().'css_assoc WHERE assoc_to_id = ? AND assoc_css_id = ?'; $ord = $db->GetOne($q1,array($id,$cssid)); // get the item with the prev ord id $q2 = 'SELECT assoc_css_id FROM '.cms_db_prefix().'css_assoc WHERE assoc_to_id = ? AND assoc_order = ?'; $other_css = $db->GetOne($q2,array($id,$ord+1)); if( $other_css ) { // swap em $q3 = 'UPDATE '.cms_db_prefix().'css_assoc SET assoc_order = ? WHERE assoc_to_id = ? AND assoc_css_id = ?'; $db->Execute($q3,array($ord,$id,$other_css)); $db->Execute($q3,array($ord+1,$id,$cssid)); } } break; } } #****************************************************************************** # displaying errors if any #****************************************************************************** if (isset($_REQUEST["message"])) { $message = trim(preg_replace('/\

'.$message.'

'; } } if ("" != $error) { echo "

".$error."

"; } if (!$addasso) { echo "

".lang('noaccessto', array(lang('addcssassociation')))."

"; } #****************************************************************************** # now really starting #****************************************************************************** else { $query = "SELECT assoc_css_id, css_name, assoc_order FROM ".cms_db_prefix()."css_assoc ca INNER JOIN ".cms_db_prefix()."css ON assoc_css_id = css_id WHERE assoc_type=? AND assoc_to_id = ? ORDER BY ca.assoc_order"; $result = $db->Execute($query, array($type, $id)); $gCms = cmsms(); $smarty = $gCms->GetSmarty(); $smarty->assign('text_move',lang('move')); $smarty->assign('text_template',lang('template')); $smarty->assign('text_title',lang('title')); $smarty->assign('edittemplate_link',''.(isset($name)?$name:"").''); $cssassoc = array(); //if ($result && $result->RecordCount() > 0) if ($result) { $count = $result->RecordCount(); $idx = 0; while( $result && $row = $result->FetchRow() ) { $csslist[] = $row["assoc_css_id"]; $tmp = array(); $url = "editcss.php".$urlext."&css_id=".$row['assoc_css_id']."&from=templatecssassoc&templateid=".$id; $tmp['editlink'] = ''.$row['css_name'].''; $tmp['editimg'] = ''.$themeObject->DisplayImage('icons/system/edit.gif',lang('editcss'),'','','systemicon').''; if( $modify ) { $downurl = 'listcssassoc.php'.$urlext.'&dir=down&cssid='.$row['assoc_css_id'].'&id='.$id.'&type=template'; $upurl = 'listcssassoc.php'.$urlext.'&dir=up&cssid='.$row['assoc_css_id'].'&id='.$id.'&type=template'; if( $idx > 0 ) { $tmp['uplink'] = ''.$themeObject->DisplayImage('icons/system/arrow-u.gif',lang('up'),'','','systemicon').''; } if( $idx + 1 < $count ) { $tmp['downlink'] = ''.$themeObject->DisplayImage('icons/system/arrow-d.gif',lang('down'),'','','systemicon').''; } $idx++; } if( $delasso ) { $tmp['deletelink'] = "".$themeObject->DisplayImage('icons/system/delete.gif', lang('delete'),'','','systemicon').""; } $cssassoc[] = $tmp; } } else { redirect('listtemplates.php'.$urlext.'&message='.lang('sqlerror', 'listcssassoc.php')); } if( count($cssassoc) ) { $smarty->assign('cssassoc',$cssassoc); } # this var is used to store the css ids that should not appear in the # dropdown $notinto = ""; foreach($csslist as $key) { $notinto .= "$key,"; } $notinto = substr($notinto, 0, strlen($notinto) - 1); # this var contains the dropdown $dropdown = ""; $result = ''; # we generate the dropdown if ("" == $notinto) { $query = "SELECT * FROM ".cms_db_prefix()."css ORDER BY css_name"; } else { $query = "SELECT * FROM ".cms_db_prefix()."css WHERE css_id NOT IN (".$notinto.") ORDER BY css_name"; } $result = $db->Execute($query); if ($result && $result->RecordCount() > 0) { $smarty->assign('formstart',"
"); $dropdown = ""; $smarty->assign('dropdown',$dropdown); $hidden = ''; $hidden .= ''; $hidden .= ''; $smarty->assign('hidden',$hidden); $submit = ''; $smarty->assign('submit',$submit); } # end of showing form } # begin output echo '
'.$themeObject->ShowHeader('currentassociations'); echo $smarty->fetch('listcssassoc.tpl'); echo '
'; echo '

« '.lang('back').'

'; include_once("footer.php"); # vim:ts=4 sw=4 noet ?>