PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/roles/edit.php

http://webberig-applications-framework.googlecode.com/
PHP | 151 lines | 132 code | 12 blank | 7 comment | 19 complexity | d36050b85345636cbf548d0d718fda13 MD5 | raw file
  1. <?php
  2. if (!$p)
  3. {
  4. $this->activeTopMenu = "settings";
  5. // Set MODE
  6. if (isset($_GET['value']))
  7. {
  8. $mode = "edit";
  9. } else
  10. {
  11. $mode = "add";
  12. }
  13. $this->subMenu = ViewMaster::Create("SubMenu");
  14. $this->subMenu->addSettings();
  15. $this->LoadLibrary("waf_forms");
  16. $form = new Waf_Form("frmSite");
  17. $input = $form->CreateInput("Text", "name");
  18. $input->label = _("Name");
  19. $input = $form->CreateInput("Text", "sequence");
  20. $input->label = _("Sequence");
  21. // Validators
  22. $validator = $form->CreateValidator("Required", "name");
  23. $validator->message = _("Name is required");
  24. if ($mode == "add")
  25. {
  26. $form->confirmation = _("New role has been created");
  27. } else {
  28. $form->confirmation = _("Roles has been updated");
  29. }
  30. $modules = Modules::GetModules();
  31. foreach ($modules as $module)
  32. {
  33. $input = $form->CreateInput("Checkbox", 'mod_'.$module['dir']);
  34. $input->label = $module['name'];
  35. $details = Modules::GetModuleSecurity($module['dir']);
  36. if (count($details))
  37. {
  38. foreach($details as $line)
  39. {
  40. $input = $form->CreateInput("Text", $module['dir'].'_'.$line[0]);
  41. $input->label = $module['name'];
  42. }
  43. }
  44. }
  45. $form->ProcessForm();
  46. if($form->isSent())
  47. {
  48. if ($form->isValid)
  49. {
  50. switch($mode)
  51. {
  52. case "edit":
  53. if (!Roles::Update($_GET['value'], $form->ToArray()))
  54. {
  55. $form->AddError(_("An unknown error occured"));
  56. }
  57. break;
  58. case "add":
  59. if (!Roles::Insert($form->ToArray()))
  60. {
  61. $form->AddError(_("An unknown error occured"));
  62. }
  63. break;
  64. }
  65. //take action
  66. if ($form->isValid)
  67. {
  68. $this->DoRedirect("roles");
  69. }
  70. }
  71. } else
  72. {
  73. // SET $form
  74. if ($mode == "edit")
  75. {
  76. //look up user
  77. if (!$item = Roles::GetRole($_GET['value']))
  78. {
  79. //record niet gevonden
  80. $this->DoRedirect("roles");
  81. }
  82. $form->SetValues($item);
  83. }
  84. else
  85. {
  86. // default values if any
  87. }
  88. }
  89. } else {
  90. $form->ShowErrors();
  91. ?>
  92. <form method="post" id="frmRole" class="wf">
  93. <div class="caption"><?php echo _("General");?></div>
  94. <fieldset>
  95. <?php
  96. $form->Show("name");
  97. $form->Show("sequence");
  98. ?>
  99. </fieldset>
  100. <div class="caption"><?php echo _("Modules");?></div>
  101. <fieldset>
  102. <?php
  103. foreach ($modules as $module)
  104. {
  105. $form->Show('mod_'.$module['dir']);
  106. $details = Modules::GetModuleSecurity($module['dir']);
  107. if (count($details))
  108. {
  109. foreach($details as $line)
  110. {
  111. $form->Show($module['dir'].'_'.$line[0]);
  112. }
  113. }
  114. }
  115. ?>
  116. </fieldset>
  117. <div class="actions">
  118. <?php
  119. if ($mode=="edit")
  120. {
  121. ?>
  122. <a class="button delete" onclick="$('#dialog-confirm').data('id', '<?php echo $_GET['value'];?>').dialog('open'); return false;" href="roles/delete/<?php echo $_GET['value'];?>">Verwijderen</a>
  123. <?php
  124. }
  125. ?>
  126. <input type="submit" value="Opslaan" />
  127. </div>
  128. </form>
  129. <?php
  130. if ($mode=="edit")
  131. {
  132. ?>
  133. <div id="dialog-confirm" title="<?php echo _("Delete role");?>">
  134. <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo _("Deleting the role will also delete all users with the given role");?>! <?php echo _("Are you sure");?>?</p>
  135. </div>
  136. <?php
  137. }
  138. }
  139. ?>