Advertisement
Guest User

Untitled

a guest
May 15th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.29 KB | None | 0 0
  1. <?php
  2. /*----------- classes/update_sorting.php -----------*/
  3.  
  4. // Simplified javascript alerts to use in PHP
  5. function alert($msg) {
  6. echo "<script type='text/javascript'>alert('$msg');</script>";
  7. }
  8.  
  9. function insert_act($user_id, $activity, $action){
  10. // Defines the Database info, change info to the websites database info before committing
  11. $dsn = 'mysql:dbname=celery;host=localhost';
  12. $user = 'root';
  13. $pass = '';
  14. c
  15. // Creates a connection to the database with database info defined above
  16. try {
  17. $connection = new PDO($dsn, $user, $pass);
  18. $connection->query("SET NAMES utf8");
  19. }catch (PDOException $exception) {
  20. echo $exception;
  21. echo "Failed to connect to database";
  22. }
  23.  
  24. $getMaster = $connection->prepare("
  25. SELECT user_main
  26. FROM users
  27. WHERE user_id=$user_id
  28. ");
  29.  
  30. if($getMaster->execute()){
  31. if($getMaster->rowCount() > 0){
  32. while($row = $getMaster->fetch()){
  33. $master_id = $row["user_main"];
  34. }
  35.  
  36. if($master_id == -1){
  37. $master_id = $user_id;
  38. }
  39.  
  40. $time = date("Y-m-d H:i:s");
  41.  
  42. $insAct = $connection->prepare("
  43. INSERT INTO log
  44. (user_id, master_id, activity, action, timestamp)
  45. VALUES (:id, :mId, :activity, :action, :time)
  46. ");
  47.  
  48. $insAct->bindValue(":id", $user_id, PDO::PARAM_STR);
  49. $insAct->bindValue(":mId", $master_id, PDO::PARAM_STR);
  50. $insAct->bindValue(":activity", $activity, PDO::PARAM_STR);
  51. $insAct->bindValue(":action", $action, PDO::PARAM_STR);
  52. $insAct->bindValue(":time", $time, PDO::PARAM_STR);
  53.  
  54. if($insAct->execute()){
  55. return true;
  56. } else {
  57. return false;
  58. }
  59. } else {
  60. return false;
  61. }
  62. } else {
  63. return false;
  64. }
  65. }
  66.  
  67. /** CONNECTION FUNCTIONS START **/
  68. function save_record($id,$order){
  69. // Defines the Database info, change info to the websites database info before committing
  70. $dsn = 'mysql:dbname=celery;host=localhost';
  71. $user = 'root';
  72. $pass = '';
  73. // Creates a connection to the database with database info defined above
  74. try {
  75. $connection = new PDO($dsn, $user, $pass);
  76. $connection->query("SET NAMES utf8");
  77. } catch (PDOException $exception) {
  78. echo $exception;
  79. echo "Failed to connect to database";
  80. }
  81.  
  82. $query = $connection->prepare("
  83. UPDATE schedule_block
  84. SET `order`=:order
  85. WHERE block_id=:id
  86. ");
  87.  
  88. $query->bindValue(":order", $order, PDO::PARAM_STR);
  89. $query->bindValue(":id", $id, PDO::PARAM_STR);
  90.  
  91. if($query->execute()){
  92.  
  93. } else {
  94.  
  95. }
  96. }
  97.  
  98. function save_recordSingle($id,$order){
  99. // Defines the Database info, change info to the websites database info before committing
  100. $dsn = 'mysql:dbname=celery;host=localhost';
  101. $user = 'root';
  102. $pass = '';
  103. // Creates a connection to the database with database info defined above
  104. try {
  105. $connection = new PDO($dsn, $user, $pass);
  106. $connection->query("SET NAMES utf8");
  107. } catch (PDOException $exception) {
  108. echo $exception;
  109. echo "Failed to connect to database";
  110. }
  111.  
  112. $query = $connection->prepare("
  113. UPDATE schedule_block_data
  114. SET `order`=:order
  115. WHERE block_data_id=:id
  116. ");
  117.  
  118. $query->bindValue(":order", $order, PDO::PARAM_STR);
  119. $query->bindValue(":id", $id, PDO::PARAM_STR);
  120.  
  121. if($query->execute()){
  122.  
  123. } else {
  124.  
  125. }
  126. }
  127.  
  128. function delete_block($id){
  129. // Defines the Database info, change info to the websites database info before committing
  130. $dsn = 'mysql:dbname=celery;host=localhost';
  131. $user = 'root';
  132. $pass = '';
  133. // Creates a connection to the database with database info defined above
  134. try {
  135. $connection = new PDO($dsn, $user, $pass);
  136. $connection->query("SET NAMES utf8");
  137. } catch (PDOException $exception) {
  138. echo $exception;
  139. echo "Failed to connect to database";
  140. }
  141.  
  142. $query = $connection->prepare("
  143. DELETE FROM schedule_block
  144. WHERE block_id=:id
  145. ");
  146.  
  147. $query->bindValue(":id", $id, PDO::PARAM_STR);
  148.  
  149. if($query->execute()){
  150.  
  151. } else {
  152.  
  153. }
  154. }
  155.  
  156. function delete_blockData($id){
  157. // Defines the Database info, change info to the websites database info before committing
  158. $dsn = 'mysql:dbname=celery;host=localhost';
  159. $user = 'root';
  160. $pass = '';
  161. // Creates a connection to the database with database info defined above
  162. try {
  163. $connection = new PDO($dsn, $user, $pass);
  164. $connection->query("SET NAMES utf8");
  165. } catch (PDOException $exception) {
  166. echo $exception;
  167. echo "Failed to connect to database";
  168. }
  169.  
  170. $query = $connection->prepare("
  171. DELETE FROM schedule_block_data
  172. WHERE block_data_id=:id
  173. ");
  174.  
  175. $query->bindValue(":id", $id, PDO::PARAM_STR);
  176.  
  177. if($query->execute()){
  178.  
  179. } else {
  180.  
  181. }
  182. }
  183.  
  184. function add_track($id, $playOnce, $block_id, $order){
  185. // Defines the Database info, change info to the websites database info before committing
  186. $dsn = 'mysql:dbname=celery;host=localhost';
  187. $user = 'root';
  188. $pass = '';
  189. // Creates a connection to the database with database info defined above
  190. try {
  191. $connection = new PDO($dsn, $user, $pass);
  192. $connection->query("SET NAMES utf8");
  193. } catch (PDOException $exception) {
  194. echo $exception;
  195. echo "Failed to connect to database";
  196. }
  197.  
  198. if($playOnce == '1'){
  199. $addTrack = $connection->prepare("
  200. INSERT INTO `schedule_block_data`
  201. (`category`, `category_type`, `order`, `schedule_block_id`)
  202. VALUES (:cat, :type, :or, :id)
  203. ");
  204.  
  205. $addTrack->bindValue(":cat", $id, PDO::PARAM_STR);
  206. $addTrack->bindValue(":type", "track", PDO::PARAM_STR);
  207. $addTrack->bindValue(":or", $order, PDO::PARAM_STR);
  208. $addTrack->bindValue(":id", $block_id, PDO::PARAM_STR);
  209.  
  210. if($addTrack->execute()){
  211. insert_act($_SESSION["user_id"], "block", "edited");
  212. } else {
  213.  
  214. }
  215. } elseif($playOnce == '2') {
  216. $checkCatType = $connection->prepare("
  217. SELECT `type`
  218. FROM `categories`
  219. WHERE cat_id=:id
  220. ");
  221.  
  222. $checkCatType->bindValue(":id", $id, PDO::PARAM_STR);
  223.  
  224. if($checkCatType->execute()){
  225. if($checkCatType->rowCount() > 0){
  226. while($row = $checkCatType->fetch()){
  227. $catType = $row["type"];
  228.  
  229. $addTrack = $connection->prepare("
  230. INSERT INTO schedule_block_data
  231. (`category`, `category_type`, `order`, `schedule_block_id`)
  232. VALUES (:cat, :type, :or, :id)
  233. ");
  234.  
  235. $addTrack->bindValue(":cat", $id, PDO::PARAM_STR);
  236. $addTrack->bindValue(":type", $catType, PDO::PARAM_STR);
  237. $addTrack->bindValue(":or", $order, PDO::PARAM_STR);
  238. $addTrack->bindValue(":id", $block_id, PDO::PARAM_STR);
  239.  
  240. if($addTrack->execute()){
  241. insert_act($_SESSION["user_id"], "block", "edited");
  242. } else {
  243.  
  244. }
  245. }
  246. } else {
  247. header("Location: new_category.php");
  248. }
  249. }
  250. }
  251. }
  252. /** CONNECTION FUNCTIONS END **/
  253.  
  254. if(isSet($_POST['token']) && $_POST['token'] == "reorder"){
  255. $data=json_decode($_POST['data']);
  256. $counter=1;
  257. foreach($data as $key=>$val){
  258. save_record($val,$counter);
  259. $counter++;
  260. }
  261. //echo "saved";
  262. }
  263. if(isSet($_POST['verwijder']) && $_POST['verwijder'] == "delete"){
  264. $data=json_decode($_POST['data']);
  265. delete_block($data);
  266. }
  267. if(isSet($_POST['verwijderSingle']) && $_POST['verwijderSingle'] == "deleteBlock"){
  268. $data=json_decode($_POST['data']);
  269. delete_blockData($data);
  270. }
  271. if(isSet($_POST['reorderSingle']) && $_POST['reorderSingle'] == "reorderSingle"){
  272. $data=json_decode($_POST['data']);
  273. $counter=1;
  274. foreach($data as $key=>$val){
  275. save_recordSingle($val,$counter);
  276. $counter++;
  277. }
  278. }
  279. if(isSet($_POST['addTrack']) && $_POST['addTrack'] == "addTrack"){
  280. $data=json_decode($_POST['data']);
  281. $id = $data->id;
  282. $playOnce = $data->type;
  283. $block_id = $data->blockId;
  284. $order = $data->order;
  285. add_track($id, $playOnce, $block_id, $order);
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement