PageRenderTime 27ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/guaardian/admin.php

#
PHP | 234 lines | 194 code | 13 blank | 27 comment | 33 complexity | 4c4f06264bdefd2f4e4454418a265a13 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. <?php
  2. session_name("interoprouter");
  3. session_start();
  4. /*
  5. * CONFIGURACAO OBRIGATORIAS
  6. * variaveis de configuracao obrigatorias para funcionamento do site
  7. */
  8. $name = "admin"; // nome da pagina atual
  9. $_SESSION["page"] = "admin.php";
  10. if ( isset( $_SESSION["lang"] ) == false ) $_SESSION["lang"] = "br";
  11. $lang = $_SESSION["lang"];
  12. /*
  13. * CONFIGURACAO
  14. * variaveis de configuracao
  15. */
  16. $gatelevel = "admin";
  17. $title = "Website";
  18. /*
  19. * CABECALHO DA PAGINA
  20. * includes e inicio da construcao do layout
  21. */
  22. ob_start(); include("modules/session.php"); ob_end_clean();
  23. ob_start(); include("modules/database.php"); ob_end_clean();
  24. ob_start(); include("template/templateBodyGen.php"); ob_end_clean();
  25. /*
  26. * CONTROLES DO CASO DE USO
  27. * funcoes que o caso de uso vai executar
  28. */
  29. //$exemplo = array("dado 1", "dado 2", "dado 3", "dado 4");
  30. if ( isset( $_GET["acao"] ) == false ) $acao = "show";
  31. else $acao = $_GET["acao"] ;
  32. if ( isset( $_GET["tabela"] ) == false ) $tabela = "accounts";
  33. else $tabela = $_GET["tabela"];
  34. switch ( $tabela )
  35. {
  36. case "accounts":
  37. switch ( $acao )
  38. {
  39. case "show":
  40. $dbSql = "SELECT * FROM accounts ORDER BY accountOwner";
  41. $dbResult = @mysql_query($dbSql);
  42. if ($dbResult == false)
  43. $flagDB = false;
  44. else
  45. {
  46. $flagDB = true;
  47. while ($dbRow = @mysql_fetch_assoc($dbResult))
  48. {
  49. $accountId = $dbRow["accountId"];
  50. $accountUser = $dbRow["accountUser"];
  51. $accountOwner = $dbRow["accountOwner"];
  52. $accountIsAdmin = ($dbRow["accountIsAdmin"] == 1) ? ("yes") : ("no");;
  53. $data[] = array("accountId" => $accountId, "accountUser" => $accountUser, "accountOwner" => $accountOwner, "accountIsAdmin" => $accountIsAdmin);
  54. }
  55. @mysql_free_result($dbResult);
  56. }
  57. break;
  58. case "remove":
  59. if ( isset( $_GET["accountId"] ) == false ) { header ("Location: admin.php?acao=show&tabela=accounts"); exit(); }
  60. $_accountId = $_GET["accountId"];
  61. $dbSql = "DELETE FROM accounts WHERE accountId=".$_accountId." LIMIT 1";
  62. $dbResult = @mysql_query($dbSql);
  63. @mysql_free_result($dbResult);
  64. header ("Location: admin.php?acao=show&tabela=accounts"); exit();
  65. break;
  66. case "add":
  67. break;
  68. case "insert":
  69. $_accountUser = $_POST["accountUser"];
  70. $_accountPassword = $_POST["accountPassword"];
  71. $_accountOwner = $_POST["accountOwner"];
  72. $_accountEmail = $_POST["accountEmail"];
  73. $_accountOrganization = $_POST["accountOrganization"];
  74. $_accountTelephone = $_POST["accountTelephone"];
  75. $dbSql = "INSERT INTO accounts (accountId, accountUser, accountPassword, accountLastLogin, accountOwner, accountEmail, accountOrganization, accountTelephone, accountIsAdmin) ";
  76. $dbSql .= "VALUES (NULL, '$_accountUser', '$_accountPassword', NOW( ) , '$_accountOwner', '$_accountEmail', '$_accountOrganization', '$_accountTelephone', '0');";
  77. $dbResult = @mysql_query($dbSql);
  78. @mysql_free_result($dbResult);
  79. header ("Location: admin.php?acao=show&tabela=accounts"); exit();
  80. break;
  81. case "edit":
  82. if ( isset( $_GET["accountId"] ) == false ) { header ("Location: admin.php?acao=show&tabela=accounts"); exit(); }
  83. $_accountId = $_GET["accountId"];
  84. $dbSql = "SELECT * FROM accounts WHERE accountId=".$_accountId." LIMIT 1";
  85. $dbResult = @mysql_query($dbSql);
  86. $data = @mysql_fetch_assoc($dbResult);
  87. @mysql_free_result($dbResult);
  88. break;
  89. case "update":
  90. $_accountId = $_POST["accountId"];
  91. $_accountUser = $_POST["accountUser"];
  92. $_accountPassword = $_POST["accountPassword"];
  93. $_accountOwner = $_POST["accountOwner"];
  94. $_accountEmail = $_POST["accountEmail"];
  95. $_accountOrganization = $_POST["accountOrganization"];
  96. $_accountTelephone = $_POST["accountTelephone"];
  97. $dbSql = "UPDATE accounts SET accountUser='$_accountUser', accountPassword='$_accountPassword', accountOwner='$_accountOwner', ";
  98. $dbSql .= " accountEmail='$_accountEmail', accountOrganization='$_accountOrganization', accountTelephone='$_accountTelephone' ";
  99. $dbSql .= " WHERE accountId='$_accountId' LIMIT 1;";
  100. $dbResult = @mysql_query($dbSql);
  101. @mysql_free_result($dbResult);
  102. header ("Location: admin.php?acao=show&tabela=accounts"); exit();
  103. break;
  104. case "admin":
  105. if ( isset( $_GET["accountId"] ) == false ) { header ("Location: admin.php?acao=show&tabela=accounts"); exit(); }
  106. $_accountId = $_GET["accountId"];
  107. $dbSql = "SELECT accountIsAdmin FROM accounts WHERE accountId=".$_accountId." LIMIT 1";
  108. $dbResult = @mysql_query($dbSql);
  109. $dbRow = @mysql_fetch_assoc($dbResult);
  110. $test = ($dbRow["accountIsAdmin"] == 1) ? (0) : (1);
  111. @mysql_free_result($dbResult);
  112. $dbSql = "UPDATE accounts SET accountIsAdmin=$test WHERE accountId='$_accountId' LIMIT 1;";
  113. $dbResult = @mysql_query($dbSql);
  114. @mysql_free_result($dbResult);
  115. header ("Location: admin.php?acao=show&tabela=accounts"); exit();
  116. break;
  117. }
  118. break;
  119. case "clusters":
  120. switch ( $acao )
  121. {
  122. case "show":
  123. $dbSql = "SELECT * FROM clusters ORDER BY clusterName";
  124. $dbResult = @mysql_query($dbSql);
  125. if ($dbResult == false)
  126. $flagDB = false;
  127. else
  128. {
  129. $flagDB = true;
  130. while ($dbRow = @mysql_fetch_assoc($dbResult))
  131. {
  132. $clusterId = $dbRow["clusterId"];
  133. $clusterName = $dbRow["clusterName"];
  134. $clusterOperationalSystem = $dbRow["clusterOperationalSystem"];
  135. $clusterActive = ($dbRow["clusterActive"] == 1) ? ("yes") : ("no");
  136. $data[] = array("clusterId" => $clusterId, "clusterName" => $clusterName, "clusterOperationalSystem" => $clusterOperationalSystem, "clusterActive" => $clusterActive);
  137. }
  138. @mysql_free_result($dbResult);
  139. }
  140. break;
  141. case "remove":
  142. if ( isset( $_GET["clusterId"] ) == false ) { header ("Location: admin.php?acao=show&tabela=clusters"); exit(); }
  143. $_clusterId = $_GET["clusterId"];
  144. $dbSql = "DELETE FROM clusters WHERE clusterId=".$_clusterId." LIMIT 1";
  145. $dbResult = @mysql_query($dbSql);
  146. @mysql_free_result($dbResult);
  147. header ("Location: admin.php?acao=show&tabela=clusters"); exit();
  148. break;
  149. case "add":
  150. break;
  151. case "insert":
  152. $_clusterName = $_POST["clusterName"];
  153. $_clusterIP = $_POST["clusterIP"];
  154. $_clusterOperationalSystem = $_POST["clusterOperationalSystem"];
  155. $_clusterScheduler = $_POST["clusterScheduler"];
  156. $_clusterProcessorModel = $_POST["clusterProcessorModel"];
  157. $_clusterNumNode = $_POST["clusterNumNode"];
  158. $_clusterNumProcessorsPerNode = $_POST["clusterNumProcessorsPerNode"];
  159. $dbSql = "INSERT INTO clusters (clusterId, clusterName, clusterIP, clusterOperationalSystem, clusterScheduler, clusterProcessorModel, clusterNumNode, clusterNumProcessorsPerNode, clusterActive, clusterTimestampAlive, clusterWorkLoad) ";
  160. $dbSql .= "VALUES (NULL, '$_clusterName', '$_clusterIP', '$_clusterOperationalSystem', '$_clusterScheduler', '$_clusterProcessorModel', '$_clusterNumNode', '$_clusterNumProcessorsPerNode', '0', NOW(), 0);";
  161. $dbResult = @mysql_query($dbSql);
  162. @mysql_free_result($dbResult);
  163. header ("Location: admin.php?acao=show&tabela=clusters"); exit();
  164. break;
  165. case "edit":
  166. if ( isset( $_GET["clusterId"] ) == false ) { header ("Location: admin.php?acao=show&tabela=clusters"); exit(); }
  167. $_clusterId = $_GET["clusterId"];
  168. $dbSql = "SELECT * FROM clusters WHERE clusterId=".$_clusterId." LIMIT 1";
  169. $dbResult = @mysql_query($dbSql);
  170. $data = @mysql_fetch_assoc($dbResult);
  171. @mysql_free_result($dbResult);
  172. break;
  173. case "update":
  174. $_clusterId = $_POST["clusterId"];
  175. $_clusterName = $_POST["clusterName"];
  176. $_clusterIP = $_POST["clusterIP"];
  177. $_clusterOperationalSystem = $_POST["clusterOperationalSystem"];
  178. $_clusterScheduler = $_POST["clusterScheduler"];
  179. $_clusterProcessorModel = $_POST["clusterProcessorModel"];
  180. $_clusterNumNode = $_POST["clusterNumNode"];
  181. $_clusterNumProcessorsPerNode = $_POST["clusterNumProcessorsPerNode"];
  182. $dbSql = "UPDATE clusters SET clusterName='$_clusterName', clusterIP='$_clusterIP', ";
  183. $dbSql .= " clusterOperationalSystem='$_clusterOperationalSystem', clusterScheduler='$_clusterScheduler', ";
  184. $dbSql .= " clusterProcessorModel='$_clusterProcessorModel', clusterNumNode='$_clusterNumNode', ";
  185. $dbSql .= " clusterNumProcessorsPerNode='$_clusterNumProcessorsPerNode' ";
  186. $dbSql .= " WHERE clusterId='$_clusterId' LIMIT 1;";
  187. $dbResult = @mysql_query($dbSql);
  188. @mysql_free_result($dbResult);
  189. header ("Location: admin.php?acao=show&tabela=clusters"); exit();
  190. break;
  191. case "active":
  192. if ( isset( $_GET["clusterId"] ) == false ) { header ("Location: admin.php?acao=show&tabela=clusters"); exit(); }
  193. $_clusterId = $_GET["clusterId"];
  194. $dbSql = "SELECT clusterActive FROM clusters WHERE clusterId=".$_clusterId." LIMIT 1";
  195. $dbResult = @mysql_query($dbSql);
  196. $dbRow = @mysql_fetch_assoc($dbResult);
  197. $test = ($dbRow["clusterActive"] == 1) ? (0) : (1);
  198. @mysql_free_result($dbResult);
  199. $dbSql = "UPDATE clusters SET clusterActive=$test WHERE clusterId='$_clusterId' LIMIT 1;";
  200. $dbResult = @mysql_query($dbSql);
  201. @mysql_free_result($dbResult);
  202. header ("Location: admin.php?acao=show&tabela=clusters"); exit();
  203. break;
  204. }
  205. break;
  206. }
  207. /*
  208. * RENDERIZA PAGINA
  209. * aqui vao os includes e as variaveis de configuracao
  210. */
  211. $javascripts = array();
  212. makeHeader($title, $javascripts);
  213. // $flagDB # database on or off
  214. // $data # all data
  215. include("lang/{$lang}/{$name}.php");
  216. /*
  217. * RODAPE DA PAGINA
  218. * encerra a pagina coma as tags necessarias
  219. */
  220. makeFooter();
  221. ?>