Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Watersys/move_category.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
64 lines (64 sloc)
1.52 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//This page let move a category | |
include('config.php'); | |
if(isset($_GET['id'], $_GET['action']) and ($_GET['action']=='up' or $_GET['action']=='down')) | |
{ | |
$id = intval($_GET['id']); | |
$action = $_GET['action']; | |
$dn1 = mysqli_fetch_array(mysqli_query($var,'select count(c.id) as nb1, c.position, count(c2.id) as nb2 from categories as c, categories as c2 where c.id="'.$id.'" group by c.id')); | |
if($dn1['nb1']>0) | |
{ | |
if(isset($_SESSION['username']) and $_SESSION['username']==$admin) | |
{ | |
if($action=='up') | |
{ | |
if($dn1['position']>1) | |
{ | |
if(mysqli_query($var,'update categories as c, categories as c2 set c.position=c.position-1, c2.position=c2.position+1 where c.id="'.$id.'" and c2.position=c.position-1')) | |
{ | |
header('Location: '.$url_home); | |
} | |
else | |
{ | |
echo 'An error occured while moving the category.'; | |
} | |
} | |
else | |
{ | |
echo '<h2>The action you want to do is impossible.</h2>'; | |
} | |
} | |
else | |
{ | |
if($dn1['position']<$dn1['nb2']) | |
{ | |
if(mysqli_query($var,'update categories as c, categories as c2 set c.position=c.position+1, c2.position=c2.position-1 where c.id="'.$id.'" and c2.position=c.position+1')) | |
{ | |
header('Location: '.$url_home); | |
} | |
else | |
{ | |
echo 'An error occured while moving the category.'; | |
} | |
} | |
else | |
{ | |
echo '<h2>The action you want to do is impossible.</h2>'; | |
} | |
} | |
} | |
else | |
{ | |
header("location:login.php?msg=Login First to use service"); | |
} | |
} | |
else | |
{ | |
echo '<h2>The category you want to move doesn\'t exist.</h2>'; | |
} | |
} | |
else | |
{ | |
header("location:login.php?msg=Login First to use service"); | |
} | |
?> |