1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
<%
'--------------------------------------------------------------------
' Description: Contain all functions declarations that work with
' the tree
'
' Arguments: None
'
'
' Error number: 1
'
' Note: Copyright © Iulian Iuga, iulian_iuga@yahoo.com
'--------------------------------------------------------------------
%>
<%
'*****************************************************************************************
' Global declarations
'*****************************************************************************************
'Const adCmdText = 1
'Const cstrConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\inetpub\wwwroot\EffectifsHR\TV\EffectifsHR.mdb;"
Const cstrConnectionString = "EFF_HR"
'Const cstrQuery = "SELECT * FROM UOBIS ORDER BY LIBL_UO, PARENT_UO"
Const cstrQuery = "SELECT DISTINCT UOBIS.UO, UOBIS.PARENT_UO, UOBIS.LIBL_UO, UOBIS.NIVEAU_UO, TBL_EFFECTIFS.UO_CODE As UoEff FROM UOBIS LEFT JOIN TBL_EFFECTIFS ON UOBIS.UO = TBL_EFFECTIFS.UO_CODE ORDER BY LIBL_UO, PARENT_UO"
Const cstrTreeNodeColor = "#B0E0E6" ' 176, 224, 230
Const cstrChildFolderMisplaced = " "
Const cstrTreeStartContainer = "<table border='0' cellpadding='0' cellspacing='2' bgcolor='#FFFFE0' width='100%'>"
Const cstrTreeEndContainer = "</table>"
'*****************************************************************************************
' Description: Read the tree stucture from the database
' Assumptions: None
' Efects: None
' Arguments: [p_strConnectionString] - string, data connection string
' [p_strQuery] - string, data query string
' Return: None
' Version: [ - Iulian Iuga]
'*****************************************************************************************
sub ReadTreeContent(p_strConnectionString, p_strQuery)
' On Error Resume Next
dim objConn
dim objRS
set objConn = server.CreateObject("ADODB.Connection")
if Err.number <> 0 then
RedirectToError ERR_CANNOT_CREATE_CONNECTION_OBJECT & "(1.1)", false
end if
objConn.Open p_strConnectionString
if Err.number <> 0 then
RedirectToError ERR_CANNOT_OPEN_DATABASE & "(1.2)", false
end if
' set objRS = objConn.Execute(p_strQuery,,adCmdText)
set objRS = objConn.Execute(p_strQuery,,1)
if Err.number <> 0 then
RedirectToError ERR_CANNOT_EXECUTE_QUERY & "(1.3)", false
end if
if not objRS.EOF then
StoreTreeContent objRS
end if
set objRS = nothing
set objConn = nothing
end sub
'*****************************************************************************************
' Description: Iterate into the recordset and store the tree values in 4 dictionary
' objects. These objects will be store in session variable.
' Assumptions: None
' Efects: None
' Arguments: [p_objRS] - object, record set
' Return: None
' Version: [ - Iulian Iuga]
'*****************************************************************************************
sub StoreTreeContent(p_objRS)
' On Error Resume Next
dim objDicParentCorespondence
dim objDicCaptionCorespondence
dim objDicTypeCorespondence
dim objDicActionCorespondence
set objDicParentCorespondence = server.CreateObject("Scripting.Dictionary")
set objDicCaptionCorespondence = server.CreateObject("Scripting.Dictionary")
set objDicTypeCorespondence = server.CreateObject("Scripting.Dictionary")
set objDicActionCorespondence = server.CreateObject("Scripting.Dictionary")
if Err.number <> 0 then
RedirectToError ERR_CANNOT_CREATE_DICTIONARY_OBJECT & "(1.4)", false
end if
while not p_objRS.EOF
dim intIDNode
dim intIDParentNode
dim strNodeCaption
dim strNodeType
dim strNodeAction
' intIDNode = p_objRS("IDNode")
intIDNode = p_objRS("UO")
' intIDParentNode = p_objRS("IDParentNode")
intIDParentNode = p_objRS("Parent_UO")
' if intIDParentNode < 0 then
if p_objRS("NIVEAU_UO") = 4 then
intIDParentNode = -1
end if
' strNodeCaption = p_objRS("NodeCaption")
strNodeCaption = "<a href='ListeCorps.asp?UO=" & p_objRS("UO") & "'>" & p_objRS("UO") & " - " & p_objRS("LIBL_UO") & "</a>"
if Not IsNull(p_objRS("UoEff")) then
strNodeCaption = strNodeCaption & "<font face=arial size=4 color=red>"
strNodeCaption = strNodeCaption & "<strong>"
strNodeCaption = strNodeCaption & " *"
strNodeCaption = strNodeCaption & "</strong>"
strNodeCaption = strNodeCaption & "</font>"
end if
' strNodeType = UCase(p_objRS("NodeType"))
' strNodeType = UCase(p_objRS("NIVEAU_UO"))
' if strNodeType <> "F" and strNodeType <> "I" then
strNodeType = "F"
' end if
' strNodeAction = p_objRS("NodeAction")
strNodeAction = p_objRS("LIBL_UO")
if IsNull(strNodeAction) then
strNodeAction = "A"
end if
objDicParentCorespondence.Add intIDNode, intIDParentNode
objDicCaptionCorespondence.Add intIDNode, strNodeCaption
objDicTypeCorespondence.Add intIDNode, strNodeType
objDicActionCorespondence.Add intIDNode, strNodeAction
p_objRS.MoveNext
if Err.number <> 0 then
RedirectToError ERR_CANNOT_OPEN_DATABASE & "(1.4)", false
end if
wend
set session("DicParentCorespondence") = objDicParentCorespondence
set session("DicCaptionCorespondence") = objDicCaptionCorespondence
set session("DicTypeCorespondence") = objDicTypeCorespondence
set session("DicActionCorespondence") = objDicActionCorespondence
set objDicParentCorespondence = nothing
set objDicCaptionCorespondence = nothing
set objDicTypeCorespondence = nothing
set objDicActionCorespondence = nothing
end sub
'*****************************************************************************************
' Description: Display the current tree structure.
' Assumptions: None
' Efects: None
' Arguments: [p_intSelectedFolder] - integer,
' Return: None
' Version: [ - Iulian Iuga]
'*****************************************************************************************
sub DisplayTree(p_intSelectedFolder)
' On Error Resume Next
dim aKeys
dim intKeysCount
dim index
aKeys = session("DicParentCorespondence").Keys
intKeysCount = session("DicParentCorespondence").Count
if Err.number <> 0 then
RedirectToError ERR_GENERAL_ERROR_MESSAGE & "(1.5)", true
end if
if p_intSelectedFolder = -1 then
Response.Write cstrTreeStartContainer
for index = 0 to intKeysCount - 1
if session("DicParentCorespondence").Item(aKeys(index)) = -1 then
DisplayNode -1, aKeys, index, false
end if
next
Response.Write cstrTreeEndContainer
else
dim aExpandedNodes()
dim intNrOfNodes
GetCurrentPath p_intSelectedFolder, aExpandedNodes, intNrOfNodes
Response.Write cstrTreeStartContainer
ExpandTree 0, intNrOfNodes, aExpandedNodes
Response.Write cstrTreeEndContainer
end if
end sub
'*****************************************************************************************
' Description: Get the path to the selected folder
' Assumptions: None
' Efects: None
' Arguments: [p_intSelectedFolder] - integer,
' <out> [p_aExpandedNodes] - array, list with nodes that must be expanded
' <out> [p_intNrOfNodes] - integer, number of expanded node
' Return: None
' Version: [ - Iulian Iuga]
'*****************************************************************************************
sub GetCurrentPath(p_intSelectedFolder, byref p_aExpandedNodes, byref p_intNrOfNodes)
' On Error Resume Next
dim intSelectedFolder
dim intNrOfNodes
dim index
dim intTmpValue
intNrOfNodes = 1
redim preserve p_aExpandedNodes(intNrOfNodes)
p_aExpandedNodes(intNrOfNodes - 1) = p_intSelectedFolder
intSelectedFolder = session("DicParentCorespondence").Item(p_intSelectedFolder)
if Err.number <> 0 then
RedirectToError ERR_GENERAL_ERROR_MESSAGE & "(1.6)", true
end if
while intSelectedFolder <> -1
intNrOfNodes = intNrOfNodes + 1
redim preserve p_aExpandedNodes(intNrOfNodes)
p_aExpandedNodes(intNrOfNodes - 1) = intSelectedFolder
intSelectedFolder = session("DicParentCorespondence").Item(intSelectedFolder)
if Err.number <> 0 then
RedirectToError ERR_GENERAL_ERROR_MESSAGE & "(1.7)", true
end if
wend
p_intNrOfNodes = intNrOfNodes - 1
' change list elements order
intNrOfNodes = p_intNrOfNodes \ 2
for index = 0 to intNrOfNodes
intTmpValue = p_aExpandedNodes(index)
p_aExpandedNodes(index) = p_aExpandedNodes(p_intNrOfNodes - index)
p_aExpandedNodes(p_intNrOfNodes - index) = intTmpValue
next
end sub
'*****************************************************************************************
' Description: Expand the tree for the current path
' Assumptions: None
' Efects: None
' Arguments: [p_intCurrentLevel] - integer,
' [p_intMaxLevel] - integer,
' [p_aExpandedNodes] - array,
' Return: None
' Version: [ - Iulian Iuga]
'*****************************************************************************************
sub ExpandTree(p_intCurrentLevel, p_intMaxLevel, p_aExpandedNodes)
'On Error Resume Next
dim aKeys
dim intKeysCount
dim index
dim index1
dim intCurrentFolder
dim intCurrentFolderParent
aKeys = session("DicParentCorespondence").Keys
intKeysCount = session("DicParentCorespondence").Count
intCurrentFolder = p_aExpandedNodes(p_intCurrentLevel)
intCurrentFolderParent = session("DicParentCorespondence").Item(intCurrentFolder)
if Err.number <> 0 then
RedirectToError ERR_GENERAL_ERROR_MESSAGE & "(1.8)", true
end if
for index = 0 to intKeysCount - 1
if aKeys(index) = intCurrentFolder then
' display selected folder
DisplayNode p_intCurrentLevel - 1, aKeys, index, true
if p_intCurrentLevel < p_intMaxLevel then
' expand tree
ExpandTree p_intCurrentLevel + 1, p_intMaxLevel, p_aExpandedNodes
else
' display all folders that are children of selected folder
for index1 = 0 to intKeysCount - 1
if session("DicParentCorespondence").Item(aKeys(index1)) = intCurrentFolder then
DisplayNode p_intCurrentLevel, aKeys, index1, false
end if
next
end if
else
' display all folders that have the same parent folder like current folder
if session("DicParentCorespondence").Item(aKeys(index)) = intCurrentFolderParent then
DisplayNode p_intCurrentLevel - 1, aKeys, index, false
end if
end if
next
end sub
'*****************************************************************************************
' Description: Disply each node with his level into the page
' Assumptions: None
' Efects: Write tree nodes into page
' Arguments: [p_intLevel] - integer,
' [p_aKeys] - array,
' [p_index] - integer,
' [p_blnSelectedFolder] - boolean,
' Return: None
' Version: [ - Iulian Iuga]
'*****************************************************************************************
sub DisplayNode(p_intLevel, p_aKeys, p_index, p_blnSelectedFolder)
' On Error Resume Next
dim index
dim strKeyAction
strKeyAction = session("DicActionCorespondence").Item(p_aKeys(p_index))
if Err.number <> 0 then
RedirectToError ERR_GENERAL_ERROR_MESSAGE & "(1.9)", true
end if
Response.Write "<tr bgcolor='" & cstrTreeNodeColor & "'><td>"
for index = 0 to p_intLevel
Response.Write cstrChildFolderMisplaced
next
if session("DicTypeCorespondence").Item(p_aKeys(p_index)) = "F" then
Response.Write "<input type='image' "
if p_blnSelectedFolder then
Response.Write "src='.\images\Openfold.gif'"
else
Response.Write "src='.\images\Clsdfold.gif'"
end if
Response.Write " name='Folder" & p_aKeys(p_index) & "' id='Folder" & p_aKeys(p_index) & "' border='0'>"
Response.Write "<b> " & session("DicCaptionCorespondence").Item(p_aKeys(p_index)) & "</b>"
else
' Response.Write "<a href='" & strKeyAction & "' style='text-decoration: none;' "
Response.Write "<a href='" & strKeyAction & "' style='text-decoration: none;' "
if UCase(Mid(strKeyAction,1,10)) = "JAVASCRIPT" then
Response.Write ">"
else
Response.Write "target='frmActionView'>"
end if
Response.Write session("DicCaptionCorespondence").Item(p_aKeys(p_index)) & "</a>"
end if
Response.Write "</td></tr>"
end sub
%> |