opers.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. require_once(dirname(dirname(__FILE__))."/header.php");
  3. function get_opers_for_current_user_obj(){
  4. global $user;
  5. return get_opers_for_user_obj($user['id']);
  6. }
  7. function get_opers_obj(){
  8. $opers = Array();
  9. $res = query("SELECT o.id FROM opers o");
  10. if($res && $res->num_rows != 0){
  11. while($oper = $res->fetch_assoc()){
  12. array_push($opers,get_oper_from_id_obj($oper['id']));
  13. }
  14. }
  15. return $opers;
  16. }
  17. function get_opers_for_user_obj($id){
  18. $opers = Array();
  19. $res = query("SELECT o.id FROM opers o WHERE o.manager_id = %d OR o.user_id = %d",Array($id,$id));
  20. if($res && $res->num_rows != 0){
  21. while($oper = $res->fetch_assoc()){
  22. array_push($opers,get_oper_from_id_obj($oper['id']));
  23. }
  24. }
  25. return $opers;
  26. }
  27. function get_oper_from_id_obj($id){
  28. $opers = Array();
  29. $res = query("SELECT o.id,o.nick,o.password,o.password_type,o.swhois,o.flags,o.user_id,o.manager_id FROM opers_v o WHERE o.id = %d",Array($id));
  30. if($res && $res->num_rows == 1){
  31. $oper = $res->fetch_assoc();
  32. $hosts = query("SELECT h.host FROM hosts h WHERE oper_id = %d",Array($oper['id']));
  33. if($hosts->num_rows != 0){
  34. $oper['hosts'] = Array();
  35. while($host = $hosts->fetch_assoc()){
  36. array_push($oper['hosts'],$host['host']);
  37. }
  38. }else{
  39. $oper['hosts'] = Array('*@*');
  40. }
  41. if(!isset($oper['user_id'])){
  42. $oper['user_id'] = '-';
  43. }
  44. return $oper;
  45. }
  46. return $opers;
  47. }
  48. function get_opers_html($opers){
  49. global $u;
  50. global $user;
  51. if(!isset($u)){
  52. $u = $user;
  53. }
  54. $ret = "";
  55. foreach($opers as $k => $oper){
  56. $ret .= "<h3>".($u['id'] != $oper['user_id']?"Managed Oper:":"Personal Oper:")."</h3>".get_form_html('oper-form-'.$oper['id'],Array(
  57. Array(
  58. 'name'=>'nick',
  59. 'label'=>'Nick',
  60. 'type'=>'text',
  61. 'value'=>$oper['nick']
  62. ),
  63. Array(
  64. 'name'=>'swhois',
  65. 'label'=>'Omnimaga Profile',
  66. 'type'=>'text',
  67. 'value'=>$oper['swhois']
  68. ),
  69. Array(
  70. 'name'=>'password',
  71. 'label'=>'New Password',
  72. 'type'=>'password',
  73. 'value'=>''
  74. ),
  75. Array(
  76. 'name'=>'id',
  77. 'type'=>'hidden',
  78. 'value'=>$oper['id']
  79. ),
  80. Array(
  81. 'name'=>'action',
  82. 'type'=>'hidden',
  83. 'value'=>'oper'
  84. )
  85. ),'Save')."<hr/>";
  86. }
  87. return $ret;
  88. }
  89. function get_opers_for_server_obj($id){
  90. $opers = Array();
  91. $res = query("SELECT o.id,o.nick,o.password,o.password_type,o.swhois,o.flags,o.role FROM opers_v o WHERE o.server_id = %d OR o.server_id IS NULL",Array($id));
  92. if($res && $res->num_rows != 0){
  93. while($oper = $res->fetch_assoc()){
  94. $hosts = query("SELECT h.host FROM hosts h WHERE oper_id = %d",Array($oper['id']));
  95. if($hosts->num_rows != 0){
  96. $oper['hosts'] = Array();
  97. while($host = $hosts->fetch_assoc()){
  98. array_push($oper['hosts'],$host['host']);
  99. }
  100. }else{
  101. $oper['hosts'] = Array('*@*');
  102. }
  103. array_push($opers,$oper);
  104. }
  105. }
  106. return $opers;
  107. }
  108. ?>