Hello, i have this code, it’s a script that can be used to save url links in a index A-Ö one can move drag and drop the links to change position, the new position is then saved in the links.php file. So this script is not using Myqsl only a flat file (links.txt) to save the links). Now if you look att the demo page you will see all the links i have i Index “temp” and want a X to the right of avery link field so if i click the X the link will bee removed. Any ideas plaease. Thank you.
Demo page: http://test3.fcab.se/links/temp/index.php
index.php:
<?php
require("../config.php");
if ($enablegzip == "1")
{
ob_start("ob_gzhandler");
header("Content-Encoding: gzip");
}
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, target-densitydpi=high-dpi">
<title>Web links - List (<?php echo basename(dirname(__FILE__));?>)</title>
<link rel=StyleSheet href="style.css" type="text/css">
<script type="text/javascript" src="../collapse_expand_single_item.js"></script>
<script type="text/javascript" src="../jquery-1.11.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
</head>
<body>
<br>
<div class="link_back">
<a href="../index.php">Back to Index</a></div>
<br>
<div class="add_link">
<a href="#first" onClick="shoh('first');">Add new link +</a></div>
<br>
<div class="index_letter"><?php echo basename(dirname(__FILE__));?></div>
<div class="add_links" style="display: none;" id="first">
<div class="box">
<br>
<form action=addurl.php method=POST name="addurlform">
<div class="box_title">Title:</div><input type=text name=text size="56" placeholder="Enter your title">
<div class="box_link">Drag & Drop Link:</div><input type=text value="" name=link size="56" placeholder="http://">
<div>
<br><br>
<input type=submit class="add_button" value="Add"></div>
</form>
<br>
</div>
</div>
<br>
<ul id="sortable">
<?php
$gbfile='links.txt';
$separator= '|';
//====================================
//This function will add one line to
//the end of file
//====================================
function add($str){
global $gbfile;
$tmp = trim($str);
$fp=fopen($gbfile,'a+');
flock($fp, LOCK_EX);
fwrite($fp, $tmp. "\
");
flock($fp, LOCK_UN);
fclose($fp);
}
//====================================
//Function below gets specified number
//of lines and returns an array
//====================================
function get($start, $end){
global $gbfile;
$records=array();
$filename="links.txt";
$fp=fopen($gbfile,'r');
flock($fp, LOCK_SH);
$i=1;
$tmp=TRUE;
while($i<$start && !feof($fp)) {
$tmp=fgets($fp);
$i++;
}
while($i<=$end && !feof($fp)) {
$tmp=trim(fgets($fp));
if ($tmp) { array_push($records, $tmp); }
$i++;
}
flock($fp, LOCK_UN);
fclose($fp);
return($records);
}
//Listing part
$start=$_GET['start'];
$end=$_GET['end'];
if (!$end || $start<=0) { $start=1; }
if (!$end) { $end=$linkspage; }
if ($end<$start) { $end=$start+1; }
$show=$end - $start;
//Get records from file into array
$records = get($start, $end);
if ($enablesort == "1")
{
sort($records);
}
//For each record get each field
foreach ($records as $rec) {
$tmp = explode($separator, $rec);
$title = $tmp[0];
$link = $tmp[1];
//=================================
//Outputting
?>
<li><a href="<?=$link?>">
<p class="title"><?php echo ("$title");?>
</p></a></li>
<?php
}
{
$start+=$show;
$end+=$show;
$start++;
$end++;
$start--;
$end--;
}
?>
</ul>
<script>
$("a[href^='http']").each(function() {
$(this).css({
background:"url(http://g.etfv.co/"+ this.href +") left center no-repeat",
"-webkit-background-size": "20px",
"-moz-background-size": "20px",
"-o-background-size": "20px",
"background-size": "20px",
"padding-left": "20px",
"margin-left": "16px"
});
});
function getLinkList(){
var list = ""
$("ul#sortable>li").each(function(){
list += $(this).find("p.title").text();
list += "|";
list += $(this).find("a").attr("href");
list += "\
";
});
return {linkList: list}
}
$( "#sortable" ).sortable({
opacity: 0.5,
update: function( event, ui ) {
$.ajax({
type: "POST",
url: "process.php",
data: getLinkList(),
dataType: "text",
success: function(res){
console.log(res)
},
});
}
});
$( "#sortable" ).disableSelection();
$('#sortable').mousedown(function(){ $(this).css('cursor', 'move');});
$('#sortable').mouseup(function(){ $(this).css('cursor', 'pointer');});
$('.title').mousedown(function(){ $(this).css('cursor', 'move');});
$('.title').mouseup(function(){ $(this).css('cursor', 'pointer');});
</script>
</body>
</html>
style.css:
a:link, a:visited, a:active { color:#282828; text-decoration:none;}
a:hover { color:#4b4b4b;}
a { display: block; text-decoration: none; width: 270px;}
form { font-family: tahoma;font-size:10pt; }
li { list-style: none; float:left; height: 42px;}
input { background-color: #eeeeee; font-family:tahoma;font-size:10pt;color:#4b4b4b;border:1px solid #4cffff; border-radius: 4px; margin-bottom: 8px; height: 22px; padding-bottom: 2px;}
input:hover { background-color: #bfffff;}
h1{color: #26C9FF;}
h3{color: #FF6347; padding-left: 30px;}
.add_link a{
font-family: Tahoma;
font-size:12pt;
color: #eee;
width: 148px;
padding-top: 10px;
text-align: center;
}
.add_link a:hover{
color: #fff;
}
.add_link {
width: 148px;
height: 42px;
margin-left: 56px;
transition: all 0.5s ease;
background-color: #333;
border-radius: 4px;
transition: all 0.5s ease;
}
.add_link:hover{
color: #fff;
cursor: pointer;
background-color: #FF6347;
padding-left: 2px;
}
.box{
margin-left: 56px;
font-size:10pt;
color:#4b4b4b;
background-color: #99FFFF;
border: 1px solid #4CFFFF;
border-radius: 4px;
padding-left: 30px;
padding-bottom: 10px;
width:396px;
height:225px;
}
.link_back{
width: 148px;
height: 42px;
margin-left: 56px;
background-color: #333;
border-radius: 4px;
cursor: pointer;
transition: all 0.5s ease;
}
.link_back:hover{
background-color: #FF6347;
padding-left: 2px;
}
.link_back a{
width: 148px;
font-family: Tahoma;
font-size:12pt;
color: #eee;
transition: all 0.5s ease;
padding-top: 10px;
text-align: center;
}
.link_back:hover a{
color: #fff;
}
.add_button{
font-family: Tahoma;
font-size:12pt;
color: #fff;
text-align: center;
width: 80px;
height: 32px;
background-color: #444;
padding-bottom: 2px;
border: 0px solid #444;
border-radius: 4px;
cursor: pointer;
transition: all 0.5s ease;
}
.add_button:hover{
background-color: #FF6347;
padding-left: 2px;
}
.box_title{
font-family: Tahoma;
font-size:12pt;
color: #4b4b4b;
}
.box_link{
font-family: Tahoma;
font-size:12pt;
color: #4b4b4b;
}
.title{
padding-left: 10px;
margin-left: 5px; /* Change this if you change the Icon size */
height: 28px;
width: 260px;
background-color: #26C9FF;
border-radius: 4px;
font-family: Tahoma;
color: #fff;
font-size:12pt;
transition: all 0.5s ease;
padding-top: 6px;
list-style-type: none;
}
.title:hover{
background-color: #FF6347;
padding-left: 8px;
}
.index_letter{
font-family: Tahoma;
FONT-SIZE:16pt;
font-weight: bold;
color: #26C9FF;
margin-left: 56px;
}
.title{
cursor:pointer;
}