PageRenderTime 31ms CodeModel.GetById 2ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/includes/save_media.php

https://bitbucket.org/mpercy/deeemm-cms
PHP | 149 lines | 111 code | 22 blank | 16 comment | 14 complexity | 0e3bb5b3193288e2313dcb08639db9ae MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause
  1. <?php
  2. defined( '_INDM' ) or die( 'POSSIBLE HACK ATTEMPT!' );
  3. /*===========================================================================
  4. Check user priviledges
  5. ===========================================================================*/
  6. require VALIDATE;
  7. if ($user != 'ADMIN') header("Location: " . $default_url . "index.php");
  8. //>get data entered in form and propogate variables
  9. //strip slashes just in case magic quotes on
  10. $library = mysql_escape_string(stripslashes($_REQUEST['parent']));
  11. $child = mysql_escape_string(stripslashes($_REQUEST['child']));
  12. $category = mysql_escape_string(stripslashes($_REQUEST['selected_category']));
  13. $title_lan_1 = mysql_escape_string(stripslashes($_REQUEST['title_lan_1']));
  14. $title_lan_2 = mysql_escape_string(stripslashes($_REQUEST['title_lan_2']));
  15. $title_lan_3 = mysql_escape_string(stripslashes($_REQUEST['title_lan_3']));
  16. $title_lan_4 = mysql_escape_string(stripslashes($_REQUEST['title_lan_4']));
  17. $tool_tip_lan_1 = mysql_escape_string(stripslashes($_REQUEST['tool_tip_lan_1']));
  18. $tool_tip_lan_2 = mysql_escape_string(stripslashes($_REQUEST['tool_tip_lan_2']));
  19. $tool_tip_lan_3 = mysql_escape_string(stripslashes($_REQUEST['tool_tip_lan_3']));
  20. $tool_tip_lan_4 = mysql_escape_string(stripslashes($_REQUEST['tool_tip_lan_4']));
  21. $description_lan_1 = mysql_escape_string(stripslashes($_REQUEST['description_lan_1']));
  22. $description_lan_2 = mysql_escape_string(stripslashes($_REQUEST['description_lan_2']));
  23. $description_lan_3 = mysql_escape_string(stripslashes($_REQUEST['description_lan_3']));
  24. $description_lan_4 = mysql_escape_string(stripslashes($_REQUEST['description_lan_4']));
  25. //>get parent field data from database entry if available
  26. $sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . 'cat_' . "$page` WHERE `id` = '$id'");
  27. while($sql_result = mysql_fetch_array($sql_query)){
  28. $old_library = $sql_result[parent];
  29. $old_image = $sql_result[image];
  30. $old_date = $sql_result[date];
  31. $old_category = $sql_result[category];
  32. }
  33. if ($_FILES['file_data']['name']) {
  34. //>upload file
  35. $destination_filepath = $default_url . $media_dir;
  36. $form_name = 'file_data';
  37. $filename = upload_file($destination_filepath, $form_name);
  38. if (!$filename){
  39. header("Location: " . $default_url . 'index.php?page=messagebox&message=upload_failed');
  40. exit;
  41. }
  42. } else {
  43. $filename = $old_image;
  44. }
  45. //>if page does not exist add data to database
  46. if ($id == '' || !isset($id) || $page == 'admin') {
  47. mysql_query("INSERT INTO `" . $db_table_prefix . $library . "` VALUES(NULL,
  48. (now()),
  49. '$order',
  50. '$library',
  51. '$title_lan_1',
  52. '$category',
  53. '$filename',
  54. '',
  55. 'on',
  56. '$title_lan_1',
  57. '$tool_tip_lan_1',
  58. '$description_lan_1',
  59. '$title_lan_2',
  60. '$tool_tip_lan_2',
  61. '$description_lan_2',
  62. '$title_lan_3',
  63. '$tool_tip_lan_3',
  64. '$description_lan_3',
  65. '$title_lan_4',
  66. '$tool_tip_lan_4',
  67. '$description_lan_4')") or die ("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql_query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());;
  68. $sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . "$library` WHERE `description_lan_1` = '$description_lan_1'");
  69. while($sql_result = mysql_fetch_array($sql_query)) $id = $sql_result[id];
  70. //$page already exists - update data in database
  71. } else {
  72. //breakpoint("'".$description_lan_1."'");
  73. //>new and old parent fields are the same - update existing entry
  74. if ($old_library == $library){
  75. // sort out order and type fields
  76. mysql_query("UPDATE `" . $db_table_prefix . $library . "` SET
  77. `child` = '$title_lan_1',
  78. `category` = '$category',
  79. `image` = '$old_image',
  80. `title_lan_1` = '$title_lan_1',
  81. `tool_tip_lan_1` = '$tool_tip_lan_1',
  82. `description_lan_1` = '$description_lan_1',
  83. `title_lan_2` = '$title_lan_2',
  84. `tool_tip_lan_2` = '$tool_tip_lan_2',
  85. `description_lan_2` = '$description_lan_2',
  86. `title_lan_3` = '$title_lan_3',
  87. `tool_tip_lan_3` = '$tool_tip_lan_3',
  88. `description_lan_3` = '$description_lan_3',
  89. `title_lan_4` = '$title_lan_4',
  90. `tool_tip_lan_4` = '$tool_tip_lan_4',
  91. `description_lan_4` = '$description_lan_4' WHERE `id` = '$id'") or die ("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql_query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());;
  92. //>else parent fields are different
  93. } else {
  94. //>so delete data from old table
  95. mysql_query("DELETE FROM `" . $db_table_prefix . "$old_library` WHERE `id` = '$id'");
  96. //>reorder id of old table by recreating field
  97. mysql_query("ALTER TABLE `" . $db_table_prefix . "$old_library` DROP `id`");
  98. mysql_query("ALTER TABLE `" . $db_table_prefix . "$old_library` ADD `id` MEDIUMINT( 16 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
  99. //>add data to new table
  100. mysql_query("INSERT INTO `" . $db_table_prefix . "$library` VALUES(NULL,
  101. '$old_date',
  102. '$order',
  103. '$library',
  104. '$title_lan_1',
  105. '$category',
  106. '$old_image',
  107. '',
  108. 'on',
  109. '$title_lan_1',
  110. '$tool_tip_lan_1',
  111. '$description_lan_1',
  112. '$title_lan_2',
  113. '$tool_tip_lan_2',
  114. '$description_lan_2',
  115. '$title_lan_3',
  116. '$tool_tip_lan_3',
  117. '$description_lan_3',
  118. '$title_lan_4',
  119. '$tool_tip_lan_4',
  120. '$description_lan_4')") or die ("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql_query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
  121. $sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . "$library` WHERE `description_lan_1` = '$description_lan_1'") or die ("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql_query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
  122. while($sql_result = mysql_fetch_array($sql_query)) $id = $sql_result[id];
  123. }
  124. }
  125. header("Location: " . $default_url . "index.php?page=$library&id=$id");
  126. exit;
  127. ?>