From: Florian G. <re...@us...> - 2008-05-06 23:08:40
|
Update of /cvsroot/perfparse/_perfparse-phpgui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13604 Modified Files: perfparse.php utils.php Log Message: Make Edit Group Deletion Policies work Index: utils.php =================================================================== RCS file: /cvsroot/perfparse/_perfparse-phpgui/utils.php,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** utils.php 24 Apr 2008 22:29:09 -0000 1.48 --- utils.php 6 May 2008 22:58:19 -0000 1.49 *************** *** 560,580 **** function get_delete_policy_parsed(&$db,$id) { $policyinfo=get_delete_policy($db,$id); ! $s=$policyinfo['delete_policy_seconds']; ! if($s<0) { // infinity ! $policyinfo['policy_seconds']=-1; ! $policyinfo['policy_minutes']=0; ! $policyinfo['policy_hours']=0; ! $policyinfo['policy_days']=0; ! return($policyinfo); ! } ! $policyinfo['policy_seconds']=$s%60; ! $s=floor($s/60); ! $policyinfo['policy_minutes']=$s%60; ! $s=floor($s/60); ! $policyinfo['policy_hours']=$s%24; ! $policyinfo['policy_days']=floor($s/24); return($policyinfo); } --- 560,587 ---- function get_delete_policy_parsed(&$db,$id) { $policyinfo=get_delete_policy($db,$id); ! $parsed=parse_seconds_to_time($policyinfo['delete_policy_seconds']); ! $policyinfo=array_merge($policyinfo,$parsed); return($policyinfo); } + // Takes a integer as input, interpretes as seconds of a time difference and returns a array + // where the time difference is more human readable in days, hours, minutes and seconds + function parse_seconds_to_time($seconds) { + if($seconds<0) { // infinity + $ret['seconds']=-1; + $ret['minutes']=0; + $ret['hours']=0; + $ret['days']=0; + } else { + $ret['seconds']=$seconds%60; + $seconds=floor($seconds/60); + $ret['minutes']=$seconds%60; + $seconds=floor($seconds/60); + $ret['hours']=$seconds%24; + $ret['days']=floor($seconds/24); + } + return($ret); + } + *************** *** 688,692 **** function get_group_bin_del_policy(&$db,$group_id) { // if policy set in group ! $query='select d.policy_name,d.delete_policy_seconds from perfdata_groups g left join perfdata_delete_policy d on g.bin_delete_policy_id=d.policy_id where g.group_id=? '; --- 695,699 ---- function get_group_bin_del_policy(&$db,$group_id) { // if policy set in group ! $query='select d.policy_name,d.delete_policy_seconds,d.policy_id from perfdata_groups g left join perfdata_delete_policy d on g.bin_delete_policy_id=d.policy_id where g.group_id=? '; *************** *** 695,699 **** } if($res['policy_name']!==NULL) { ! return(array('source'=>'Group Policy','policy_name'=>$res['policy_name'],'policy_seconds'=>$res['delete_policy_seconds'])); } return(array('source'=>'none')); --- 702,707 ---- } if($res['policy_name']!==NULL) { ! return(array('source'=>'Group Policy','policy_name'=>$res['policy_name'],'policy_seconds'=>$res['delete_policy_seconds'], ! 'policy_id'=>$res['policy_id'])); } return(array('source'=>'none')); *************** *** 702,706 **** function get_group_raw_del_policy(&$db,$group_id) { // if policy set in group ! $query='select d.policy_name,d.delete_policy_seconds from perfdata_groups g left join perfdata_delete_policy d on g.raw_delete_policy_id=d.policy_id where g.group_id=? '; --- 710,714 ---- function get_group_raw_del_policy(&$db,$group_id) { // if policy set in group ! $query='select d.policy_name,d.delete_policy_seconds,d.policy_id from perfdata_groups g left join perfdata_delete_policy d on g.raw_delete_policy_id=d.policy_id where g.group_id=? '; *************** *** 709,717 **** } if($res['policy_name']!==NULL) { ! return(array('source'=>'Group Policy','policy_name'=>$res['policy_name'],'policy_seconds'=>$res['delete_policy_seconds'])); } return(array('source'=>'none')); } function get_group_bin_del_policy_from_hostid(&$db,$host_id) { --- 717,755 ---- } if($res['policy_name']!==NULL) { ! return(array('source'=>'Group Policy','policy_name'=>$res['policy_name'],'policy_seconds'=>$res['delete_policy_seconds'], ! 'policy_id'=>$res['policy_id'])); } return(array('source'=>'none')); } + function set_group_bin_del_policy(&$db,$group_id,$policy_id) { + // sanitize + $group_id=(int) $group_id; + if(empty($policy_id) or $policy_id===NULL) { + $policy_id=NULL; + } else { + $policy_id=(int) $policy_id; + } + $query='update perfdata_groups set bin_delete_policy_id=? where group_id=?'; + if(!$res=$db->Execute($query,array($policy_id,$group_id))) { + return(FALSE); + } + return(TRUE); + } + + function set_group_raw_del_policy(&$db,$group_id,$policy_id) { + // sanitize + $group_id=(int) $group_id; + if(empty($policy_id) or $policy_id===NULL) { + $policy_id=NULL; + } else { + $policy_id=(int) $policy_id; + } + $query='update perfdata_groups set raw_delete_policy_id=? where group_id=?'; + if(!$res=$db->Execute($query,array($policy_id,$group_id))) { + return(FALSE); + } + return(TRUE); + } function get_group_bin_del_policy_from_hostid(&$db,$host_id) { Index: perfparse.php =================================================================== RCS file: /cvsroot/perfparse/_perfparse-phpgui/perfparse.php,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** perfparse.php 1 Apr 2008 19:22:26 -0000 1.63 --- perfparse.php 6 May 2008 22:58:19 -0000 1.64 *************** *** 611,615 **** --- 611,669 ---- break; + case 'edit_group_delete_policies': + get_request_var('edited','int',FALSE); + if($edited) { + get_request_var('change_bin_del_policy','array'); + get_request_var('change_raw_del_policy','array'); + if(isset($_REQUEST['change_all'])) { + // read every value and set it + foreach($change_bin_del_policy as $groupId=>$policyId) { + set_group_bin_del_policy($db,$groupId,$policyId); + } + foreach($change_raw_del_policy as $groupId=>$policyId) { + set_group_raw_del_policy($db,$groupId,$policyId); + } + } else { + get_request_var('change_del_policy','array'); + foreach($change_del_policy as $groupId=>$dummy) { + set_group_bin_del_policy($db,$groupId,$change_bin_del_policy[$groupId]); + set_group_raw_del_policy($db,$groupId,$change_raw_del_policy[$groupId]); + } + } + } + + + // Get data for displaying table + $policyinfos=get_delete_policies($db); + $groupinfos=get_groups($db); + foreach($groupinfos as $groupid => $groupname) { + $groupinfos[$groupid]=array('groupname'=>$groupname); + $t=get_group_bin_del_policy($db,$groupid); + if($t['source'] != 'none') { + $parsed=parse_seconds_to_time($t['policy_seconds']); // not needed? + $t=array_merge($t,$parsed); + $groupinfos[$groupid]['bin_policy']=$t; + } else { + $groupinfos[$groupid]['bin_policy']['policy_name']=''; + $groupinfos[$groupid]['bin_policy']['policy_seconds']=''; + } + $t=get_group_raw_del_policy($db,$groupid); + if($t['source'] != 'none') { + $parsed=parse_seconds_to_time($t['policy_seconds']); // not needed? + $t=array_merge($t,$parsed); + $groupinfos[$groupid]['raw_policy']=$t; + } else { + $groupinfos[$groupid]['raw_policy']['policy_name']=''; + $groupinfos[$groupid]['raw_policy']['policy_seconds']=''; + } + } + + + $smarty->assign_by_ref('groupinfos',$groupinfos); + $smarty->assign_by_ref('policyinfos',$policyinfos); + $smarty->display($config['PHP_Style'].$_REQUEST['page'].'.tpl.html'); + break; + case 'show_effective_del_policies': // get all needed object names and ids |