Commit c041d149c7bb28ee7683414315849ea9b70cb667
1 parent
6060dbba
WSA-3
"Error occurs in >>ktws_eg_folder_listing.php<<" Fixed. Rewrote get_listing() to accomodate anonymous. Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6822 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
142 additions
and
103 deletions
ktapi/KTAPIConstants.inc.php
| ... | ... | @@ -68,5 +68,6 @@ define('KTAPI_PERMISSION_RENAME_FOLDER', 'ktcore.permissions.folder_rename'); |
| 68 | 68 | define('KTAPI_PERMISSION_CHANGE_OWNERSHIP', 'ktcore.permissions.security'); |
| 69 | 69 | define('KTAPI_PERMISSION_DOCUMENT_MOVE', 'ktcore.permissions.write'); |
| 70 | 70 | define('KTAPI_PERMISSION_WORKFLOW', 'ktcore.permissions.workflow'); |
| 71 | +define('KTAPI_PERMISSION_VIEW_FOLDER', 'ktcore.permissions.folder_details'); | |
| 71 | 72 | |
| 72 | 73 | ?> |
| 73 | 74 | \ No newline at end of file | ... | ... |
ktapi/KTAPIFolder.inc.php
| ... | ... | @@ -232,127 +232,161 @@ class KTAPI_Folder extends KTAPI_FolderItem |
| 232 | 232 | return $this->_get_document_by_name($documentname,'getByFilenameAndFolder'); |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - function get_listing($depth=1, $what='DF') | |
| 235 | + function _resolve_user($userid) | |
| 236 | 236 | { |
| 237 | + $user=null; | |
| 238 | + | |
| 239 | + if (!is_null($userid)) | |
| 240 | + { | |
| 241 | + $user=User::get($userid); | |
| 242 | + if (is_null($user) || PEAR::isError($user)) | |
| 243 | + { | |
| 244 | + $user=null; | |
| 245 | + } | |
| 246 | + } | |
| 247 | + return $user; | |
| 248 | + } | |
| 249 | + | |
| 250 | + | |
| 251 | + function get_listing($depth=1, $what='DF') | |
| 252 | + { | |
| 237 | 253 | if ($depth < 1) |
| 238 | 254 | { |
| 239 | 255 | return array(); |
| 240 | 256 | } |
| 241 | - $permission = &KTPermission::getByName(KTAPI_PERMISSION_READ); | |
| 242 | - $permissionid= $permission->getId(); | |
| 243 | 257 | |
| 244 | - $user = $this->ktapi->get_user(); | |
| 245 | - $descriptors=KTPermissionUtil::getPermissionDescriptorsForUser($user); | |
| 246 | - if (is_null($descriptors) || PEAR::isError($descriptors)) | |
| 247 | - { | |
| 248 | - return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR . ': problem with descriptors for user', $descriptors); | |
| 249 | - } | |
| 250 | - if (count($descriptors == 0)) | |
| 251 | - { | |
| 252 | - $descriptors=array(0); | |
| 253 | - } | |
| 258 | + $what = strtoupper($what); | |
| 259 | + $read_permission = &KTPermission::getByName(KTAPI_PERMISSION_READ); | |
| 260 | + $folder_permission = &KTPermission::getByName(KTAPI_PERMISSION_VIEW_FOLDER); | |
| 261 | + | |
| 254 | 262 | |
| 255 | - $aPermissionDescriptors = implode(',',$descriptors); | |
| 263 | + $user = $this->ktapi->get_user(); | |
| 264 | + | |
| 265 | + $contents = array(); | |
| 256 | 266 | |
| 257 | - $sql = ''; | |
| 258 | - if (strpos($what,'D') !== false) | |
| 259 | - { | |
| 260 | - $sql .= "SELECT | |
| 261 | - d.id, | |
| 262 | - 'D' as item_type, | |
| 263 | - dmv.name as title, | |
| 264 | - ifnull(uc.name, 'n/a') AS creator, | |
| 265 | - ifnull(cou.name, 'n/a') AS checkedoutby, | |
| 266 | - ifnull(mu.name, 'n/a') AS modifiedby, | |
| 267 | - dcv.filename, | |
| 268 | - dcv.size, | |
| 269 | - dcv.major_version, | |
| 270 | - dcv.minor_version, | |
| 271 | - dcv.storage_path, | |
| 272 | - ifnull(mt.mimetypes, 'unknown') as mime_type, | |
| 273 | - ifnull(mt.icon_path, 'unknown') as mime_icon_path, | |
| 274 | - ifnull(mt.friendly_name, 'unknown') as mime_display | |
| 275 | - FROM | |
| 276 | - documents d | |
| 277 | - INNER JOIN permission_lookups AS PL ON d.permission_lookup_id = PL.id | |
| 278 | - INNER JOIN permission_lookup_assignments AS PLA ON PL.id = PLA.permission_lookup_id AND PLA.permission_id = $permissionid | |
| 279 | - INNER JOIN document_metadata_version AS dmv ON d.metadata_version_id=dmv.id | |
| 280 | - INNER JOIN document_content_version AS dcv ON dmv.content_version_id=dcv.id | |
| 281 | - LEFT OUTER JOIN mime_types mt ON dcv.mime_id = mt.id | |
| 282 | - LEFT OUTER JOIN users AS uc ON d.creator_id=uc.id | |
| 283 | - LEFT OUTER JOIN users AS cou ON d.checked_out_user_id=cou.id | |
| 284 | - LEFT OUTER JOIN users AS mu ON d.modified_user_id=mu.id | |
| 285 | - WHERE | |
| 286 | - d.folder_id=$this->folderid | |
| 287 | - AND d.status_id = 1 | |
| 288 | - AND PLA.permission_descriptor_id IN ($aPermissionDescriptors)"; | |
| 289 | - } | |
| 290 | - | |
| 291 | 267 | if (strpos($what,'F') !== false) |
| 292 | 268 | { |
| 293 | - if (strpos($what,'D') !== false) | |
| 269 | + $folder_children = Folder::getList(array('parent_id = ?', $this->folderid)); | |
| 270 | + | |
| 271 | + | |
| 272 | + foreach ($folder_children as $folder) | |
| 294 | 273 | { |
| 295 | - $sql .= ' UNION '; | |
| 274 | + if(KTPermissionUtil::userHasPermissionOnItem($user, $folder_permission, $folder)) | |
| 275 | + { | |
| 276 | + $creator=$this->_resolve_user($folder->getCreatorID()); | |
| 277 | + | |
| 278 | + if ($depth-1 > 0) | |
| 279 | + { | |
| 280 | + $sub_folder = &$this->ktapi->get_folder_by_id($folder->getId()); | |
| 281 | + $items = $folder->get_listing($depth-1); | |
| 282 | + } | |
| 283 | + else | |
| 284 | + { | |
| 285 | + $items=array(); | |
| 286 | + } | |
| 287 | + | |
| 288 | + | |
| 289 | + $contents[] = array( | |
| 290 | + 'id' => (int) $folder->getId(), | |
| 291 | + 'item_type'=>'F', | |
| 292 | + 'title'=>$folder->getName(), | |
| 293 | + 'creator'=>is_null($creator)?'n/a':$creator->getName(), | |
| 294 | + 'checkedoutby'=>'n/a', | |
| 295 | + 'modifiedby'=>'n/a', | |
| 296 | + 'filename'=>$folder->getName(), | |
| 297 | + 'size'=>'n/a', | |
| 298 | + 'major_version'=>'n/a', | |
| 299 | + 'minor_version'=>'n/a', | |
| 300 | + 'storage_path'=>'n/a', | |
| 301 | + 'mime_type'=>'folder', | |
| 302 | + 'mime_icon_path'=>'folder', | |
| 303 | + 'mime_display'=>'Folder', | |
| 304 | + 'items'=>$items, | |
| 305 | + 'workflow'=>'n/a', | |
| 306 | + 'workflow_state'=>'n/a' | |
| 307 | + | |
| 308 | + ); | |
| 309 | + } | |
| 296 | 310 | } |
| 297 | - | |
| 298 | - $sql .= " | |
| 299 | - SELECT | |
| 300 | - f.id, | |
| 301 | - 'F' as item_type, | |
| 302 | - f.name as title, | |
| 303 | - ifnull(uc.name, 'n/a') AS creator, | |
| 304 | - 'n/a' checkedoutby, | |
| 305 | - 'n/a' AS modifiedby, | |
| 306 | - f.name as filename, | |
| 307 | - 'n/a' as size, | |
| 308 | - 'n/a' as major_version, | |
| 309 | - 'n/a' as minor_version, | |
| 310 | - 'n/a' as storage_path, | |
| 311 | - 'folder' as mime_type, | |
| 312 | - 'folder' as mime_icon_path, | |
| 313 | - 'Folder' as mime_display | |
| 314 | - FROM | |
| 315 | - folders f | |
| 316 | - INNER JOIN permission_lookups AS PL ON f.permission_lookup_id = PL.id | |
| 317 | - INNER JOIN permission_lookup_assignments AS PLA ON PL.id = PLA.permission_lookup_id AND PLA.permission_id = $permissionid | |
| 318 | - LEFT OUTER JOIN users AS uc ON f.creator_id=uc.id | |
| 319 | - | |
| 320 | - WHERE | |
| 321 | - f.parent_id=$this->folderid | |
| 322 | - | |
| 323 | - AND PLA.permission_descriptor_id IN ($aPermissionDescriptors) | |
| 324 | - ORDER BY item_type DESC, title, filename | |
| 325 | - "; | |
| 326 | - } | |
| 327 | - | |
| 328 | - $contents = DBUtil::getResultArray($sql); | |
| 329 | - if (is_null($contents) || PEAR::isError($contents)) | |
| 330 | - { | |
| 331 | - return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR , $contents); | |
| 332 | 311 | } |
| 333 | - | |
| 334 | - $num_items = count($contents); | |
| 335 | - for($i=0;$i<$num_items;$i++) | |
| 312 | + if (strpos($what,'D') !== false) | |
| 336 | 313 | { |
| 337 | - $contents[$i]['id'] = (int) $contents[$i]['id']; | |
| 338 | - if ($contents[$i]['item_type'] == 'D') | |
| 339 | - { | |
| 340 | - $contents[$i]['items'] = array(); | |
| 341 | - } | |
| 342 | - else | |
| 314 | + $document_children = Document::getList(array('folder_id = ? AND status_id = 1', $this->folderid)); | |
| 315 | + | |
| 316 | + // I hate that KT doesn't cache things nicely... | |
| 317 | + $mime_cache=array(); | |
| 318 | + | |
| 319 | + foreach ($document_children as $document) | |
| 343 | 320 | { |
| 344 | - if ($depth-1 > 0) | |
| 321 | + if (KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $document)) | |
| 345 | 322 | { |
| 346 | - $folder = &$this->ktapi->get_folder_by_id($item['id']); | |
| 347 | - $contents[$i]['items'] = $folder->get_listing($depth-1); | |
| 348 | - } | |
| 349 | - else | |
| 350 | - { | |
| 351 | - $contents[$i]['items'] = array(); | |
| 323 | + $creator=$this->_resolve_user($document->getCreatorID()); | |
| 324 | + $checkedoutby=$this->_resolve_user($document->getCheckedOutUserID()); | |
| 325 | + $modifiedby=$this->_resolve_user($document->getCreatorID()); | |
| 326 | + | |
| 327 | + $mimetypeid=$document->getMimeTypeID(); | |
| 328 | + if (!array_key_exists($mimetypeid, $mime_cache)) | |
| 329 | + { | |
| 330 | + | |
| 331 | + $type=KTMime::getMimeTypeName($mimetypeid); | |
| 332 | + $icon=KTMime::getIconPath($mimetypeid); | |
| 333 | + $display=KTMime::getFriendlyNameForString($type); | |
| 334 | + $mime_cache[$mimetypeid] = array( | |
| 335 | + 'type'=>$type, | |
| 336 | + 'icon'=>$icon, | |
| 337 | + 'display'=>$display | |
| 338 | + | |
| 339 | + ); | |
| 340 | + } | |
| 341 | + $mimeinfo=$mime_cache[$mimetypeid]; | |
| 342 | + | |
| 343 | + $workflow = KTWorkflowUtil::getWorkflowForDocument($document); | |
| 344 | + | |
| 345 | + if (!is_null($workflow) && !PEAR::isError($workflow)) | |
| 346 | + { | |
| 347 | + $workflow=$workflow->getHumanName(); | |
| 348 | + | |
| 349 | + $state=KTWorkflowUtil::getWorkflowStateForDocument($document); | |
| 350 | + if (!is_null($state) && !PEAR::isError($state)) | |
| 351 | + { | |
| 352 | + $state=$state->getHumanName(); | |
| 353 | + } | |
| 354 | + else | |
| 355 | + { | |
| 356 | + $state='n/a'; | |
| 357 | + } | |
| 358 | + } | |
| 359 | + else | |
| 360 | + { | |
| 361 | + $workflow='n/a'; | |
| 362 | + $state='n/a'; | |
| 363 | + } | |
| 364 | + | |
| 365 | + | |
| 366 | + $contents[] = array( | |
| 367 | + 'id' => (int) $document->getId(), | |
| 368 | + 'item_type'=>'D', | |
| 369 | + 'title'=>$document->getName(), | |
| 370 | + 'creator'=>is_null($creator)?'n/a':$creator->getName(), | |
| 371 | + 'checkedoutby'=>is_null($checkedoutby)?'n/a':$checkedoutby->getName(), | |
| 372 | + 'modifiedby'=>is_null($modifiedby)?'n/a':$modifiedby->getName(), | |
| 373 | + 'filename'=>$document->getName(), | |
| 374 | + 'size'=>$document->getFileSize(), | |
| 375 | + 'major_version'=>$document->getMajorVersionNumber(), | |
| 376 | + 'minor_version'=>$document->getMinorVersionNumber(), | |
| 377 | + 'storage_path'=>$document->getStoragePath(), | |
| 378 | + 'mime_type'=>$mime_cache[$mimetypeid]['type'], | |
| 379 | + 'mime_icon_path'=>$mime_cache[$mimetypeid]['icon'], | |
| 380 | + 'mime_display'=>$mime_cache[$mimetypeid]['display'], | |
| 381 | + 'items'=>array(), | |
| 382 | + 'workflow'=>$workflow, | |
| 383 | + 'workflow_state'=>$state | |
| 384 | + ); | |
| 352 | 385 | } |
| 353 | 386 | } |
| 387 | + | |
| 354 | 388 | } |
| 355 | - | |
| 389 | + | |
| 356 | 390 | return $contents; |
| 357 | 391 | } |
| 358 | 392 | ... | ... |
ktapi/KTAPISession.inc.php
| ... | ... | @@ -266,7 +266,11 @@ class KTAPI_UserSession extends KTAPI_Session |
| 266 | 266 | $sql = "UPDATE active_sessions SET last_used='$now' WHERE id=$sessionid"; |
| 267 | 267 | DBUtil::runQuery($sql); |
| 268 | 268 | |
| 269 | - $session = &new KTAPI_UserSession($ktapi, $user, $session, $sessionid, $ip); | |
| 269 | + | |
| 270 | + if ($user->isAnonymous()) | |
| 271 | + $session = &new KTAPI_AnonymousSession($ktapi, $user, $session, $sessionid, $ip); | |
| 272 | + else | |
| 273 | + $session = &new KTAPI_UserSession($ktapi, $user, $session, $sessionid, $ip); | |
| 270 | 274 | return $session; |
| 271 | 275 | } |
| 272 | 276 | ... | ... |