/photographer/menu_creator.php

https://github.com/GansukhB/phtstr · PHP · 231 lines · 206 code · 15 blank · 10 comment · 33 complexity · 0b671fcf6d7892d2edbc50d7751cf57d MD5 · raw file

  1. <?PHP
  2. session_start();
  3. session_register("mgruser");
  4. $_SESSION['mgruser'] = 1;
  5. include( "../database.php" );
  6. include( "../config_public.php" );
  7. include( "../functions.php" );
  8. //$lang = $_SESSION['lang'];
  9. echo $_SESSION['lang'];
  10. $lang = explode(".", $_SESSION['lang'] );
  11. $lang = strtolower($lang[0]);
  12. unset($_SESSION['mgruser']);
  13. $cr = "\n";
  14. if($setting->show_private != 1){
  15. $extrasql = " and pub_pri = '0'";
  16. } else {
  17. $extrasql = "";
  18. }
  19. if($setting->show_num == 1){
  20. $show = 1;
  21. } else {
  22. $show = 0;
  23. }
  24. $output = "var TREE_ITEMS = [";
  25. $output.= $cr . "['". $left_select_cat . "', '', {'tt' : '" . $left_select_cat_hover . "', 'sb':'Select A Category','hte':{'oncontextmenu':'return h_context_menu_root(o_tree_item)','style':'color:" . $left_select_cat_color . "'}},";
  26. // level one output (main category)----------------------------------------
  27. //$ca_result = mysql_query("SELECT title,id,pub_pri,rdmcode FROM photo_galleries where active = '1' and nest_under = '0'" . $extrasql . " order by galorder", $db);
  28. $ca_result = mysql_query("SELECT * FROM photo_galleries where active = '1' and nest_under = '0'" . $extrasql . " order by galorder", $db);
  29. $ca_rows = mysql_num_rows($ca_result);
  30. while($ca = mysql_fetch_object($ca_result)){
  31. $title1 = $ca->title;
  32. if($_GET['lang'] != "English" )
  33. {
  34. if($ca->{'title_'.$_GET['lang']} != "")
  35. $title1 = $ca->{'title_'.$_GET['lang']};
  36. }
  37. //addslashes($title1);
  38. htmlspecialchars($title1);
  39. $output.= $cr . "['" . addslashes($title1);
  40. if($setting->show_num == 1){
  41. $output.= imgcount($ca->id,1,0,$item_id,0,$setting->show_private);
  42. $output.= " (" .$photo_rows_final . ")', ";
  43. $photo_rows_final = 0;
  44. } else {
  45. $output.= "', ";
  46. }
  47. if($ca->pub_pri == 1){
  48. $output.= "'" . $setting->site_url . "/pri.php?gid=" . $ca->id . "&gal=" . $ca->rdmcode . "',,";
  49. } else {
  50. if($setting->modrw){
  51. $output.= "'" . $setting->site_url . "/" . mod_clean($ca->title) . "_g" . $ca->id . ".html',,";
  52. } else {
  53. $output.= "'" . $setting->site_url . "/gallery.php?gid=" . $ca->id . "',,";
  54. }
  55. }
  56. // level two output (sub category)------------------------------------------
  57. $ca2_result = mysql_query("SELECT title,id,pub_pri,rdmcode FROM photo_galleries where active = '1' and nest_under = '$ca->id'" . $extrasql . " order by galorder", $db);
  58. $ca2_rows = mysql_num_rows($ca2_result);
  59. if($ca2_rows == 0){
  60. $output.= "],";
  61. } else {
  62. while($ca2 = mysql_fetch_object($ca2_result)){
  63. $title2 = $ca2->title;
  64. //addslashes($title2);
  65. htmlspecialchars($title2);
  66. $output.= $cr . "['" . addslashes($title2);
  67. if($setting->show_num == 1){
  68. $output.= imgcount($ca2->id,1,0,$item_id,0,$setting->show_private);
  69. $output.= " (" .$photo_rows_final . ")', ";
  70. $photo_rows_final = 0;
  71. } else {
  72. $output.= "', ";
  73. }
  74. if($ca2->pub_pri == 1){
  75. $output.= "'" . $setting->site_url . "/pri.php?gid=" . $ca2->id . "&gal=" . $ca2->rdmcode . "',,";
  76. } else {
  77. //$output.= "'" . $setting->site_url . "/gallery.php?gid=" . $ca2->id . "',,";
  78. if($setting->modrw){
  79. $output.= "'" . $setting->site_url . "/" . mod_clean($ca2->title) . "_g" . $ca2->id . ".html',,";
  80. } else {
  81. $output.= "'" . $setting->site_url . "/gallery.php?gid=" . $ca2->id . "',,";
  82. }
  83. }
  84. // level three output (sub sub category)-----------------------------------
  85. $ca3_result = mysql_query("SELECT title,id,pub_pri,rdmcode FROM photo_galleries where active = '1' and nest_under = '$ca2->id'" . $extrasql . " order by galorder", $db);
  86. $ca3_rows = mysql_num_rows($ca3_result);
  87. if($ca3_rows == 0){
  88. $output.= "],";
  89. } else {
  90. while($ca3 = mysql_fetch_object($ca3_result)){
  91. $title3 = $ca3->title;
  92. //addslashes($title3);
  93. htmlspecialchars($title3);
  94. $output.= $cr . "['" . addslashes($title3);
  95. if($setting->show_num == 1){
  96. $output.= imgcount($ca3->id,1,0,$item_id,0,$setting->show_private);
  97. $output.= " (" .$photo_rows_final . ")', ";
  98. $photo_rows_final = 0;
  99. } else {
  100. $output.= "', ";
  101. }
  102. if($ca3->pub_pri == 1){
  103. $output.= "'" . $setting->site_url . "/pri.php?gid=" . $ca3->id . "&gal=" . $ca3->rdmcode . "',,";
  104. } else {
  105. //$output.= "'" . $setting->site_url . "/gallery.php?gid=" . $ca3->id . "',,";
  106. if($setting->modrw){
  107. $output.= "'" . $setting->site_url . "/" . mod_clean($ca3->title) . "_g" . $ca3->id . ".html',,";
  108. } else {
  109. $output.= "'" . $setting->site_url . "/gallery.php?gid=" . $ca3->id . "',,";
  110. }
  111. }
  112. // level four output (sub sub sub category)--------------------------------
  113. $ca4_result = mysql_query("SELECT title,id,pub_pri,rdmcode FROM photo_galleries where active = '1' and nest_under = '$ca3->id'" . $extrasql . " order by galorder", $db);
  114. $ca4_rows = mysql_num_rows($ca4_result);
  115. if($ca4_rows == 0){
  116. $output.= "],";
  117. } else {
  118. while($ca4 = mysql_fetch_object($ca4_result)){
  119. $title4 = $ca4->title;
  120. //addslashes($title4);
  121. htmlspecialchars($title4);
  122. $output.= $cr . "['" . addslashes($title4);
  123. if($setting->show_num == 1){
  124. $output.= imgcount($ca4->id,1,0,$item_id,0,$setting->show_private);
  125. $output.= " (" .$photo_rows_final . ")', ";
  126. $photo_rows_final = 0;
  127. } else {
  128. $output.= "', ";
  129. }
  130. if($ca4->pub_pri == 1){
  131. $output.= "'" . $setting->site_url . "/pri.php?gid=" . $ca4->id . "&gal=" . $ca4->rdmcode . "',,";
  132. } else {
  133. //$output.= "'" . $setting->site_url . "/gallery.php?gid=" . $ca4->id . "',,";
  134. if($setting->modrw){
  135. $output.= "'" . $setting->site_url . "/" . mod_clean($ca4->title) . "_g" . $ca4->id . ".html',,";
  136. } else {
  137. $output.= "'" . $setting->site_url . "/gallery.php?gid=" . $ca4->id . "',,";
  138. }
  139. }
  140. // level five output (sub sub sub sub category)------------------------------
  141. $ca5_result = mysql_query("SELECT title,id,pub_pri,rdmcode FROM photo_galleries where active = '1' and nest_under = '$ca4->id'" . $extrasql . " order by galorder", $db);
  142. $ca5_rows = mysql_num_rows($ca5_result);
  143. if($ca5_rows == 0){
  144. $output.= "],";
  145. } else {
  146. while($ca5 = mysql_fetch_object($ca5_result)){
  147. $title5 = $ca5->title;
  148. //addslashes($title5);
  149. htmlspecialchars($title5);
  150. $output.= $cr . "['" . addslashes($title5);
  151. if($setting->show_num == 1){
  152. $output.= imgcount($ca5->id,1,0,$item_id,0,$setting->show_private);
  153. $output.= " (" .$photo_rows_final . ")', ";
  154. $photo_rows_final = 0;
  155. } else {
  156. $output.= "', ";
  157. }
  158. if($ca5->pub_pri == 1){
  159. $output.= "'" . $setting->site_url . "/pri.php?gid=" . $ca5->id . "&gal=" . $ca5->rdmcode . "'],";
  160. } else {
  161. //$output.= "'" . $setting->site_url . "/gallery.php?gid=" . $ca5->id . "'],";
  162. if($setting->modrw){
  163. $output.= "'" . $setting->site_url . "/" . mod_clean($ca5->title) . "_g" . $ca5->id . ".html'],";
  164. } else {
  165. $output.= "'" . $setting->site_url . "/gallery.php?gid=" . $ca5->id . "'],";
  166. }
  167. }
  168. }
  169. $output.= $cr . "],";
  170. }
  171. }
  172. $output.= $cr . "],";
  173. }
  174. }
  175. $output.= $cr . "],";
  176. }
  177. }
  178. $output.= $cr . "],";
  179. }
  180. }
  181. $output.= $cr . "]";
  182. $output.= $cr . "];";
  183. $filename = '../js/tree_items_'.$_GET['lang'].'.js';
  184. //if(!file_exists($filename))
  185. fopen($filename, 'a+');
  186. $content = $output;
  187. if (is_writable($filename)) {
  188. if (!$handle = fopen($filename, 'a+')) {
  189. echo "Cannot open file ($filename)";
  190. exit;
  191. }
  192. if (fwrite($handle, $content) === FALSE) {
  193. echo "<html>";
  194. echo "<body>";
  195. echo "Cannot write to file ($filename) check the folder permission<br>";
  196. echo "<font face=\"arial\" size=\"2\"><a href=\"javascript:window.close()\">There was an issue writing to file, do you wish to close this window?</a></font>";
  197. echo "</body>";
  198. echo "</html>";
  199. exit;
  200. }
  201. echo "<html>";
  202. echo "<body>";
  203. echo "Success, wrote menu to file ($filename)<br>";
  204. echo "<font face=\"arial\" size=\"2\"><a href=\"javascript:window.close()\">The menu was created successfully, do you wish to close this window?</a></font>";
  205. echo "</body>";
  206. echo "</html>";
  207. fclose($handle);
  208. } else {
  209. echo "The file $filename is not writable check the file permission";
  210. }
  211. ?>