Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*----------- classes/update_sorting.php -----------*/
- // Simplified javascript alerts to use in PHP
- function alert($msg) {
- echo "<script type='text/javascript'>alert('$msg');</script>";
- }
- function insert_act($user_id, $activity, $action){
- // Defines the Database info, change info to the websites database info before committing
- $dsn = 'mysql:dbname=celery;host=localhost';
- $user = 'root';
- $pass = '';
- c
- // Creates a connection to the database with database info defined above
- try {
- $connection = new PDO($dsn, $user, $pass);
- $connection->query("SET NAMES utf8");
- }catch (PDOException $exception) {
- echo $exception;
- echo "Failed to connect to database";
- }
- $getMaster = $connection->prepare("
- SELECT user_main
- FROM users
- WHERE user_id=$user_id
- ");
- if($getMaster->execute()){
- if($getMaster->rowCount() > 0){
- while($row = $getMaster->fetch()){
- $master_id = $row["user_main"];
- }
- if($master_id == -1){
- $master_id = $user_id;
- }
- $time = date("Y-m-d H:i:s");
- $insAct = $connection->prepare("
- INSERT INTO log
- (user_id, master_id, activity, action, timestamp)
- VALUES (:id, :mId, :activity, :action, :time)
- ");
- $insAct->bindValue(":id", $user_id, PDO::PARAM_STR);
- $insAct->bindValue(":mId", $master_id, PDO::PARAM_STR);
- $insAct->bindValue(":activity", $activity, PDO::PARAM_STR);
- $insAct->bindValue(":action", $action, PDO::PARAM_STR);
- $insAct->bindValue(":time", $time, PDO::PARAM_STR);
- if($insAct->execute()){
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- /** CONNECTION FUNCTIONS START **/
- function save_record($id,$order){
- // Defines the Database info, change info to the websites database info before committing
- $dsn = 'mysql:dbname=celery;host=localhost';
- $user = 'root';
- $pass = '';
- // Creates a connection to the database with database info defined above
- try {
- $connection = new PDO($dsn, $user, $pass);
- $connection->query("SET NAMES utf8");
- } catch (PDOException $exception) {
- echo $exception;
- echo "Failed to connect to database";
- }
- $query = $connection->prepare("
- UPDATE schedule_block
- SET `order`=:order
- WHERE block_id=:id
- ");
- $query->bindValue(":order", $order, PDO::PARAM_STR);
- $query->bindValue(":id", $id, PDO::PARAM_STR);
- if($query->execute()){
- } else {
- }
- }
- function save_recordSingle($id,$order){
- // Defines the Database info, change info to the websites database info before committing
- $dsn = 'mysql:dbname=celery;host=localhost';
- $user = 'root';
- $pass = '';
- // Creates a connection to the database with database info defined above
- try {
- $connection = new PDO($dsn, $user, $pass);
- $connection->query("SET NAMES utf8");
- } catch (PDOException $exception) {
- echo $exception;
- echo "Failed to connect to database";
- }
- $query = $connection->prepare("
- UPDATE schedule_block_data
- SET `order`=:order
- WHERE block_data_id=:id
- ");
- $query->bindValue(":order", $order, PDO::PARAM_STR);
- $query->bindValue(":id", $id, PDO::PARAM_STR);
- if($query->execute()){
- } else {
- }
- }
- function delete_block($id){
- // Defines the Database info, change info to the websites database info before committing
- $dsn = 'mysql:dbname=celery;host=localhost';
- $user = 'root';
- $pass = '';
- // Creates a connection to the database with database info defined above
- try {
- $connection = new PDO($dsn, $user, $pass);
- $connection->query("SET NAMES utf8");
- } catch (PDOException $exception) {
- echo $exception;
- echo "Failed to connect to database";
- }
- $query = $connection->prepare("
- DELETE FROM schedule_block
- WHERE block_id=:id
- ");
- $query->bindValue(":id", $id, PDO::PARAM_STR);
- if($query->execute()){
- } else {
- }
- }
- function delete_blockData($id){
- // Defines the Database info, change info to the websites database info before committing
- $dsn = 'mysql:dbname=celery;host=localhost';
- $user = 'root';
- $pass = '';
- // Creates a connection to the database with database info defined above
- try {
- $connection = new PDO($dsn, $user, $pass);
- $connection->query("SET NAMES utf8");
- } catch (PDOException $exception) {
- echo $exception;
- echo "Failed to connect to database";
- }
- $query = $connection->prepare("
- DELETE FROM schedule_block_data
- WHERE block_data_id=:id
- ");
- $query->bindValue(":id", $id, PDO::PARAM_STR);
- if($query->execute()){
- } else {
- }
- }
- function add_track($id, $playOnce, $block_id, $order){
- // Defines the Database info, change info to the websites database info before committing
- $dsn = 'mysql:dbname=celery;host=localhost';
- $user = 'root';
- $pass = '';
- // Creates a connection to the database with database info defined above
- try {
- $connection = new PDO($dsn, $user, $pass);
- $connection->query("SET NAMES utf8");
- } catch (PDOException $exception) {
- echo $exception;
- echo "Failed to connect to database";
- }
- if($playOnce == '1'){
- $addTrack = $connection->prepare("
- INSERT INTO `schedule_block_data`
- (`category`, `category_type`, `order`, `schedule_block_id`)
- VALUES (:cat, :type, :or, :id)
- ");
- $addTrack->bindValue(":cat", $id, PDO::PARAM_STR);
- $addTrack->bindValue(":type", "track", PDO::PARAM_STR);
- $addTrack->bindValue(":or", $order, PDO::PARAM_STR);
- $addTrack->bindValue(":id", $block_id, PDO::PARAM_STR);
- if($addTrack->execute()){
- insert_act($_SESSION["user_id"], "block", "edited");
- } else {
- }
- } elseif($playOnce == '2') {
- $checkCatType = $connection->prepare("
- SELECT `type`
- FROM `categories`
- WHERE cat_id=:id
- ");
- $checkCatType->bindValue(":id", $id, PDO::PARAM_STR);
- if($checkCatType->execute()){
- if($checkCatType->rowCount() > 0){
- while($row = $checkCatType->fetch()){
- $catType = $row["type"];
- $addTrack = $connection->prepare("
- INSERT INTO schedule_block_data
- (`category`, `category_type`, `order`, `schedule_block_id`)
- VALUES (:cat, :type, :or, :id)
- ");
- $addTrack->bindValue(":cat", $id, PDO::PARAM_STR);
- $addTrack->bindValue(":type", $catType, PDO::PARAM_STR);
- $addTrack->bindValue(":or", $order, PDO::PARAM_STR);
- $addTrack->bindValue(":id", $block_id, PDO::PARAM_STR);
- if($addTrack->execute()){
- insert_act($_SESSION["user_id"], "block", "edited");
- } else {
- }
- }
- } else {
- header("Location: new_category.php");
- }
- }
- }
- }
- /** CONNECTION FUNCTIONS END **/
- if(isSet($_POST['token']) && $_POST['token'] == "reorder"){
- $data=json_decode($_POST['data']);
- $counter=1;
- foreach($data as $key=>$val){
- save_record($val,$counter);
- $counter++;
- }
- //echo "saved";
- }
- if(isSet($_POST['verwijder']) && $_POST['verwijder'] == "delete"){
- $data=json_decode($_POST['data']);
- delete_block($data);
- }
- if(isSet($_POST['verwijderSingle']) && $_POST['verwijderSingle'] == "deleteBlock"){
- $data=json_decode($_POST['data']);
- delete_blockData($data);
- }
- if(isSet($_POST['reorderSingle']) && $_POST['reorderSingle'] == "reorderSingle"){
- $data=json_decode($_POST['data']);
- $counter=1;
- foreach($data as $key=>$val){
- save_recordSingle($val,$counter);
- $counter++;
- }
- }
- if(isSet($_POST['addTrack']) && $_POST['addTrack'] == "addTrack"){
- $data=json_decode($_POST['data']);
- $id = $data->id;
- $playOnce = $data->type;
- $block_id = $data->blockId;
- $order = $data->order;
- add_track($id, $playOnce, $block_id, $order);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement