PageRenderTime 60ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/htroot/manager/frames/nodes.php

https://github.com/gunf/novo-isaak.local
PHP | 207 lines | 172 code | 19 blank | 16 comment | 58 complexity | d6980f08cda88391e2fa51f5f0f1a4eb MD5 | raw file
  1. <?php
  2. /**
  3. * Tree Nodes
  4. * Build and return document tree view nodes
  5. *
  6. */
  7. if(IN_MANAGER_MODE!="true") die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the MODx Content Manager instead of accessing this file directly.");
  8. // save folderstate
  9. if (isset($_GET['opened'])) $_SESSION['openedArray'] = $_GET['opened'];
  10. if (isset($_GET['savestateonly'])) {
  11. echo 'send some data'; //??
  12. exit;
  13. }
  14. $indent = $_GET['indent'];
  15. $parent = $_GET['parent'];
  16. $expandAll = $_GET['expandAll'];
  17. $output = "";
  18. $theme = $manager_theme ? "$manager_theme/":"";
  19. // setup sorting
  20. if(isset($_REQUEST['tree_sortby'])) {
  21. $_SESSION['tree_sortby'] = $_REQUEST['tree_sortby'];
  22. }
  23. if(isset($_REQUEST['tree_sortdir'])) {
  24. $_SESSION['tree_sortdir'] = $_REQUEST['tree_sortdir'];
  25. }
  26. // icons by content type
  27. $icons = array(
  28. 'application/rss+xml' => $_style["tree_page_rss"],
  29. 'application/pdf' => $_style["tree_page_pdf"],
  30. 'application/vnd.ms-word' => $_style["tree_page_word"],
  31. 'application/vnd.ms-excel' => $_style["tree_page_excel"],
  32. 'text/css' => $_style["tree_page_css"],
  33. 'text/html' => $_style["tree_page_html"],
  34. 'text/plain' => $_style["tree_page"],
  35. 'text/xml' => $_style["tree_page_xml"],
  36. 'text/javascript' => $_style["tree_page_js"],
  37. 'image/gif' => $_style["tree_page_gif"],
  38. 'image/jpg' => $_style["tree_page_jpg"],
  39. 'image/png' => $_style["tree_page_png"]
  40. );
  41. $iconsPrivate = array(
  42. 'application/rss+xml' => $_style["tree_page_rss_secure"],
  43. 'application/pdf' => $_style["tree_page_pdf_secure"],
  44. 'application/vnd.ms-word' => $_style["tree_page_word_secure"],
  45. 'application/vnd.ms-excel' => $_style["tree_page_excel_secure"],
  46. 'text/css' => $_style["tree_page_css_secure"],
  47. 'text/html' => $_style["tree_page_html_secure"],
  48. 'text/plain' => $_style["tree_page_secure"],
  49. 'text/xml' => $_style["tree_page_xml_secure"],
  50. 'text/javascript' => $_style["tree_page_js_secure"],
  51. 'image/gif' => $_style["tree_page_gif_secure"],
  52. 'image/jpg' => $_style["tree_page_jpg_secure"],
  53. 'image/png' => $_style["tree_page_png_secure"]
  54. );
  55. if (isset($_SESSION['openedArray'])) {
  56. $opened = explode("|", $_SESSION['openedArray']);
  57. } else {
  58. $opened = array();
  59. }
  60. $opened2 = array();
  61. $closed2 = array();
  62. makeHTML($indent,$parent,$expandAll,$theme);
  63. echo $output;
  64. // check for deleted documents on reload
  65. if ($expandAll==2) {
  66. $sql = "SELECT COUNT(*) FROM $dbase.`".$table_prefix."site_content` WHERE deleted=1";
  67. $rs = mysql_query($sql);
  68. $row = mysql_fetch_row($rs);
  69. $count = $row[0];
  70. if ($count>0) echo '<span id="binFull"></span>'; // add a special element to let system now that the bin is full
  71. }
  72. function makeHTML($indent,$parent,$expandAll,$theme) {
  73. global $modx;
  74. global $icons, $iconsPrivate, $theme, $_style;
  75. global $modxDBConn, $output, $dbase, $table_prefix, $_lang, $opened, $opened2, $closed2; //added global vars
  76. $pad = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  77. // setup spacer
  78. $spacer = "";
  79. for ($i = 1; $i <= $indent; $i++){
  80. $spacer .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  81. }
  82. if (!isset($_SESSION['tree_sortby']) && !isset($_SESSION['tree_sortdir'])) {
  83. // This is the first startup, set default sort order
  84. $_SESSION['tree_sortby'] = 'menuindex';
  85. $_SESSION['tree_sortdir'] = 'ASC';
  86. }
  87. $orderby = $_SESSION['tree_sortby']." ".$_SESSION['tree_sortdir'];
  88. // Folder sorting gets special setup ;) Add menuindex and pagetitle
  89. if($_SESSION['tree_sortby'] == 'isfolder') $orderby .= ", menuindex ASC, pagetitle";
  90. $tblsc = $dbase.".`".$table_prefix."site_content`";
  91. $tbldg = $dbase.".`".$table_prefix."document_groups`";
  92. $tbldgn = $dbase.".`".$table_prefix."documentgroup_names`";
  93. // get document groups for current user
  94. if($_SESSION['mgrDocgroups']) $docgrp = implode(",",$_SESSION['mgrDocgroups']);
  95. $showProtected= false;
  96. if (isset ($modx->config['tree_show_protected'])) {
  97. $showProtected= (boolean) $modx->config['tree_show_protected'];
  98. }
  99. $mgrRole= (isset ($_SESSION['mgrRole']) && (string) $_SESSION['mgrRole']==='1') ? '1' : '0';
  100. if ($showProtected == false) {
  101. $access = "AND (1={$mgrRole} OR sc.privatemgr=0".
  102. (!$docgrp ? ")":" OR dg.document_group IN ({$docgrp}))");
  103. }
  104. $sql = "SELECT DISTINCT sc.id, pagetitle, parent, isfolder, published, deleted, type, menuindex, hidemenu, alias, contentType, privateweb, privatemgr,
  105. MAX(IF(1={$mgrRole} OR sc.privatemgr=0" . (!$docgrp ? "":" OR dg.document_group IN ({$docgrp})") . ", 1, 0)) AS has_access
  106. FROM {$tblsc} AS sc
  107. LEFT JOIN {$tbldg} dg on dg.document = sc.id
  108. WHERE (parent={$parent})
  109. $access
  110. GROUP BY sc.id
  111. ORDER BY {$orderby}";
  112. $result = mysql_query($sql, $modxDBConn);
  113. if(mysql_num_rows($result)==0) {
  114. $output .= '<div style="white-space: nowrap;">'.$spacer.$pad.'<img align="absmiddle" src="'.$_style["tree_deletedpage"].'">&nbsp;<span class="emptyNode">'.$_lang['empty_folder'].'</span></div>';
  115. }
  116. // Make sure to pass in the $modx_textdir variable to the node builder
  117. global $modx_textdir;
  118. while(list($id,$pagetitle,$parent,$isfolder,$published,$deleted,$type,$menuindex,$hidemenu,$alias,$contenttype,$privateweb,$privatemgr,$hasAccess) = mysql_fetch_row($result))
  119. {
  120. $pagetitle = htmlspecialchars(str_replace(array("\r\n", "\n", "\r"), '', $pagetitle));
  121. $protectedClass = $hasAccess==0 ? ' protectedNode' : '';
  122. $pagetitleDisplay = $published==0 ? "<span class=\"unpublishedNode\">$pagetitle</span>" : ($hidemenu==1 ? "<span class=\"notInMenuNode$protectedClass\">$pagetitle</span>":"<span class=\"publishedNode$protectedClass\">$pagetitle</span>");
  123. $pagetitleDisplay = $deleted==1 ? "<span class=\"deletedNode\">$pagetitle</span>" : $pagetitleDisplay;
  124. $weblinkDisplay = $type=="reference" ? '&nbsp;<img src="'.$_style["tree_linkgo"].'">' : '' ;
  125. $pageIdDisplay = '<small>('.($modx_textdir ? '&rlm;':'').$id.')</small>';
  126. $url = $modx->makeUrl($id);
  127. $alt = !empty($alias) ? $_lang['alias'].": ".$alias : $_lang['alias'].": -";
  128. $alt.= " ".$_lang['resource_opt_menu_index'].": ".$menuindex;
  129. $alt.= " ".$_lang['resource_opt_show_menu'].": ".($hidemenu==1 ? $_lang['no']:$_lang['yes']);
  130. $alt.= " ".$_lang['page_data_web_access'].": ".($privateweb ? $_lang['private']:$_lang['public']);
  131. $alt.= " ".$_lang['page_data_mgr_access'].": ".($privatemgr ? $_lang['private']:$_lang['public']);
  132. if (!$isfolder) {
  133. $icon = ($privateweb||$privatemgr) ? $_style["tree_page_secure"] : $_style["tree_page"];
  134. if ($privateweb||$privatemgr) {
  135. if (isset($iconsPrivate[$contenttype])) {
  136. $icon = $iconsPrivate[$contenttype];
  137. }
  138. } else {
  139. if (isset($icons[$contenttype])) {
  140. $icon = $icons[$contenttype];
  141. }
  142. }
  143. if($id == $modx->config['site_start']) $icon = $_style["tree_page_home"];
  144. elseif($id == $modx->config['error_page']) $icon = $_style["tree_page_404"];
  145. elseif($id == $modx->config['site_unavailable_page']) $icon = $_style["tree_page_hourglass"];
  146. elseif($id == $modx->config['unauthorized_page']) $icon = $_style["tree_page_info"];
  147. $output .= '<div id="node'.$id.'" p="'.$parent.'" style="white-space: nowrap;">'.$spacer.$pad.'<img id="p'.$id.'" align="absmiddle" title="'.$_lang['click_to_context'].'" style="cursor: pointer" src="'.$icon.'" onclick="showPopup('.$id.',\''.addslashes($pagetitle).'\',event);return false;" oncontextmenu="this.onclick(event);return false;" onmouseover="setCNS(this, 1)" onmouseout="setCNS(this, 0)" onmousedown="itemToChange='.$id.'; selectedObjectName=\''.addslashes($pagetitle).'\'; selectedObjectDeleted='.$deleted.'; selectedObjectUrl=\''.$url.'\'" />&nbsp;';
  148. $output .= '<span p="'.$parent.'" onclick="treeAction('.$id.', \''.addslashes($pagetitle).'\'); setSelected(this);" onmouseover="setHoverClass(this, 1);" onmouseout="setHoverClass(this, 0);" class="treeNode" onmousedown="itemToChange='.$id.'; selectedObjectName=\''.addslashes($pagetitle).'\'; selectedObjectDeleted='.$deleted.'; selectedObjectUrl=\''.$url.'\';" oncontextmenu="document.getElementById(\'p'.$id.'\').onclick(event);return false;" title="'.addslashes($alt).'">'.$pagetitleDisplay.$weblinkDisplay.'</span> '.$pageIdDisplay.'</div>';
  149. }
  150. else {
  151. // expandAll: two type for partial expansion
  152. if ($expandAll ==1 || ($expandAll == 2 && in_array($id, $opened)))
  153. {
  154. if ($expandAll == 1) {
  155. array_push($opened2, $id);
  156. }
  157. if($id == $modx->config['site_start']) $icon = $_style["tree_page_home"];
  158. elseif($id == $modx->config['error_page']) $icon = $_style["tree_page_404"];
  159. elseif($id == $modx->config['site_unavailable_page']) $icon = $_style["tree_page_hourglass"];
  160. elseif($id == $modx->config['unauthorized_page']) $icon = $_style["tree_page_info"];
  161. $output .= '<div id="node'.$id.'" p="'.$parent.'" style="white-space: nowrap;">'.$spacer.'<img id="s'.$id.'" align="absmiddle" style="cursor: pointer" src="'.$_style["tree_minusnode"].'" onclick="toggleNode(this,'.($indent+1).','.$id.',0,'. (($privateweb == 1 || $privatemgr == 1) ? '1' : '0') .'); return false;" oncontextmenu="this.onclick(event); return false;" />&nbsp;<img id="f'.$id.'" align="absmiddle" title="'.$_lang['click_to_context'].'" style="cursor: pointer" src="'.(($privateweb == 1 || $privatemgr == 1) ? $_style["tree_folderopen_secure"] : $_style["tree_folderopen"]).'" onclick="showPopup('.$id.',\''.addslashes($pagetitle).'\',event);return false;" oncontextmenu="this.onclick(event);return false;" onmouseover="setCNS(this, 1)" onmouseout="setCNS(this, 0)" onmousedown="itemToChange='.$id.'; selectedObjectName=\''.addslashes($pagetitle).'\'; selectedObjectDeleted='.$deleted.'; selectedObjectUrl=\''.$url.'\';" />&nbsp;';
  162. $output .= '<span onclick="treeAction('.$id.', \''.addslashes($pagetitle).'\'); setSelected(this);" onmouseover="setHoverClass(this, 1);" onmouseout="setHoverClass(this, 0);" class="treeNode" onmousedown="itemToChange='.$id.'; selectedObjectName=\''.addslashes($pagetitle).'\'; selectedObjectDeleted='.$deleted.'; selectedObjectUrl=\''.$url.'\';" oncontextmenu="document.getElementById(\'f'.$id.'\').onclick(event);return false;" title="'.addslashes($alt).'">'.$pagetitleDisplay.$weblinkDisplay.'</span> '.$pageIdDisplay.'<div style="display:block">';
  163. makeHTML($indent+1,$id,$expandAll,$theme);
  164. $output .= '</div></div>';
  165. }
  166. else {
  167. $output .= '<div id="node'.$id.'" p="'.$parent.'" style="white-space: nowrap;">'.$spacer.'<img id="s'.$id.'" align="absmiddle" style="cursor: pointer" src="'.$_style["tree_plusnode"].'" onclick="toggleNode(this,'.($indent+1).','.$id.',0,'. (($privateweb == 1 || $privatemgr == 1) ? '1' : '0') .'); return false;" oncontextmenu="this.onclick(event); return false;" />&nbsp;<img id="f'.$id.'" title="'.$_lang['click_to_context'].'" align="absmiddle" style="cursor: pointer" src="'.(($privateweb == 1 || $privatemgr == 1) ? $_style["tree_folder_secure"] : $_style["tree_folder"]).'" onclick="showPopup('.$id.',\''.addslashes($pagetitle).'\',event);return false;" oncontextmenu="this.onclick(event);return false;" onmouseover="setCNS(this, 1)" onmouseout="setCNS(this, 0)" onmousedown="itemToChange='.$id.'; selectedObjectName=\''.addslashes($pagetitle).'\'; selectedObjectDeleted='.$deleted.'; selectedObjectUrl=\''.$url.'\';" />&nbsp;';
  168. $output .= '<span onclick="treeAction('.$id.', \''.addslashes($pagetitle).'\'); setSelected(this);" onmouseover="setHoverClass(this, 1);" onmouseout="setHoverClass(this, 0);" class="treeNode" onmousedown="itemToChange='.$id.'; selectedObjectName=\''.addslashes($pagetitle).'\'; selectedObjectDeleted='.$deleted.'; selectedObjectUrl=\''.$url.'\';" oncontextmenu="document.getElementById(\'f'.$id.'\').onclick(event);return false;" title="'.addslashes($alt).'">'.$pagetitleDisplay.$weblinkDisplay.'</span> '.$pageIdDisplay.'<div style="display:none"></div></div>';
  169. array_push($closed2, $id);
  170. }
  171. }
  172. // store vars in Javascript
  173. if ($expandAll == 1) {
  174. echo '<script type="text/javascript"> ';
  175. foreach ($opened2 as $item) {
  176. printf("parent.openedArray[%d] = 1; ", $item);
  177. }
  178. echo '</script> ';
  179. } elseif ($expandAll == 0) {
  180. echo '<script type="text/javascript"> ';
  181. foreach ($closed2 as $item) {
  182. printf("parent.openedArray[%d] = 0; ", $item);
  183. }
  184. echo '</script> ';
  185. }
  186. }
  187. }
  188. ?>