getResourceTypeByRID($rid); } $typeDesc = get_type_desc($type); _load_file($typeDesc['pluginID'], $typeDesc['typeID']); $robj = new $typeDesc['typeID']($rid); $next = _do_act($robj); } return $next; } function _do_act($robj) { global $krihvel, $kdb, $user; $robj->setKrihvel($krihvel); $robj->setDB($kdb); $robj->setUser($user); foreach ($_POST as $vrbl => $val ) { if ( substr($vrbl, 0, 6) == "action" ) { $next = array('pid' => 'insufficentpermissions'); // TODO: test me if ( method_exists($robj, $vrbl) ) { $reflection = new ReflectionAnnotatedClass($robj); $meth = new ReflectionAnnotatedMethod($robj, $vrbl); if ( $meth->hasAnnotation('Secured') ) { $an = $meth->getAnnotation('Secured'); $rolesOk = False; if ( $an->roles ) { $hasRoles = $user->hasAnyRole($an->roles); if ( $hasRoles ) { $rolesOk = True; } } else { $rolesOk = True; } if ( !$rolesOk ) { return $next; } $validOk = False; if ( $an->valid ) { foreach ( $an->valid as $vmeth ) { if ( method_exists($robj, $vmeth) ) { $bol = call_user_func(array($robj, $vmeth)); if ( !$bol ) { $validOk = True; } else { $validOk = False; break; } } else { $validOk = False; break; } } } else { $validOk = True; } if ( !$validOk ) { return $next; } $next = call_user_func(array($robj, $vrbl)); } } return $next; } } } function _get_page($id) { global $pages2; if ( $pages2 == null ) { global $kdb; $pages2 = $kdb->getPages(); } foreach ( $pages2 as $page ) { if ( !strcmp($page['pageID'], $id) ) { return $page; } } return null; } function has_page($id) { $p = _get_page($id); if ( $p != null ) { return True; } return False; } function render_menu_rid($rid) { global $krihvel, $kdb; $co = $krihvel->getCurrentDataObject(); if ( isset($co) ) { $type = $kdb->getResourceTypeByRID($rid); _render_menu_group($co->getType(), $co->getResourceID(), $co); //_render_menu_group($type, $rid); } } function render_menu($pageid) { global $krihvel, $pages, $user, $menus; // get page's class $p = _get_page($pageid); $group = $p['grps']; _render_menu_group($group, -1, $krihvel->getCurrPage()); } function _fetchmodes($refl, $obj) { $res = array(); if ( $refl->hasAnnotation('Mode') ) { $anns = $refl->getAllAnnotations('Mode'); foreach($anns as $ann) { $tmp = array(); $vals = ''; if ( $ann->valid ) { $vals = implode(",", $ann->valid); } $tmp['title'] = $ann->title; $tmp['page'] = '&mode='.$ann->mode; $tmp['mode'] = $ann->mode; if ( $ann->roles ) { $tmp['roles'] = implode(",", $ann->roles); } if ( $ann->valid ) { $tmp['valid'] = implode(",", $ann->valid); } $tmp['exclude'] = $ann->exclude_from_nav; array_push($res, $tmp); } } $par = $refl->getParentClass(); if ( $par ) { $modes = _fetchmodes($par, $obj); $filtered = array(); foreach( $modes as $mode ) { $ext = False; foreach( $res as $re ) { if ( $re['mode'] == $mode['mode'] ) { $ext = True; } } if ( !$ext ) { $filtered[] = $mode; } } $res = array_merge($res, $filtered); } return $res; } function _render_menu_group($group, $rid, $context) { $current = $_SERVER['QUERY_STRING']; global $kdb, $krihvel, $user; $refl = new ReflectionAnnotatedClass($context); $elem = ""; $elems = $kdb->getMenuElements('leftmenu', $group); foreach ( $elems as $item ) { $llink = $item['page']; if ( $rid > 0 && strpos($llink, "?") === false) { $llink = "?rid=".$rid.$llink; } $active = ""; if (!strcmp(str_replace("&back", "", $llink), "?".$current)) { $active = "menuItemNaviBookActive"; } $valret = 0; if ( isset($item['valid']) && strlen($item['valid']) > 0 ) { $validators = preg_split("/,/", $item['valid']); if ( count($validators) > 0 ) { foreach($validators as $vali) { if ( method_exists($context, $vali) ) { $valret += call_user_func(array($context, $vali)); } else { } } } } if ( isset($item['roles'])) { $mroles = preg_split("/,/", $item['roles']); } else { $mroles = array(); } if ( $valret == 0 && $user->hasAnyRole($mroles) ) { if ( $rid == "new" && strpos($llink, "?") === false ) { continue; } $elem .= "
"; } } $disabled = ""; $trans = gettext("Back"); $history = $krihvel->getHistory(); $ahref = "".$trans.""; if ($_SESSION['krihvel_history_page']<=0) { $disabled = "menuItemNaviBookDisabled"; $ahref = $trans; } $elem .= " "; $elem .= ""; $add_elems = $kdb->getMenuElements('action', $group); $elems = array_merge(_fetchmodes($refl, $context), $add_elems); foreach ( $elems as $item ) { if ( isset($item['exclude']) && $item['exclude'] ) { continue; } $llink = $item['page']; if ( $rid > 0 && strpos($llink, "?") === false) { $llink = "?rid=".$rid.$llink; } $active = ""; if (!strcmp(str_replace("&back", "", $llink), "?".str_replace("&back", "", $current))) { $active = "menuItemActionBookActive"; } $valret = 0; if ( isset($item['valid']) && strlen($item['valid']) > 0 ) { $validators = preg_split("/,/", $item['valid']); if ( count($validators) > 0 ) { foreach($validators as $vali) { if ( method_exists($context, $vali) ) { $valret += call_user_func(array($context, $vali)); } else { } } } } if ( isset($item['roles'])) { $mroles = preg_split("/,/", $item['roles']); } else { $mroles = array(); } if ( $valret == 0 && $user->hasAnyRole($mroles) ) { if ( $rid == "new" && strpos($llink, "?") === false ) { continue; } $elem .= " "; } } $tomenu = "leftmenu"; if ( isset($item['menu']) && $item['menu']!='action') { $tomenu = $item['menu']; } $krihvel->out($tomenu, $elem); } function get_tasks() { global $kdb; return $kdb->getTasks(); } function get_type_desc($typeName) { global $kdb; return $kdb->getType($typeName); } function getTypeIcon($typeName, $rid) { global $types; $tt = get_type_desc($typeName); if ( $tt['icon_method'] != NULL ) { _load_file($tt['pluginID'], $tt['typeID']); $o = new $tt['typeID']; return call_user_func($tt['typeID']."::".$tt['icon_method'], $rid); } else { return $tt['icon']; } } ?>