PageRenderTime 59ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/includes/save_content.php

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