PageRenderTime 62ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/administrators.php

https://github.com/validoc/Pikmas
PHP | 199 lines | 161 code | 28 blank | 10 comment | 32 complexity | cac6a7d4123bd1818662478defbba45c MD5 | raw file
  1. <?php
  2. /*
  3. $Id: administrators.php 1739 2007-12-20 00:52:16Z hpdl $
  4. osCommerce, Open Source E-Commerce Solutions
  5. http://www.oscommerce.com
  6. Copyright (c) 2007 osCommerce
  7. Released under the GNU General Public License
  8. */
  9. require('includes/application_top.php');
  10. $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  11. if (tep_not_null($action)) {
  12. switch ($action) {
  13. case 'insert':
  14. require('includes/functions/password_funcs.php');
  15. $username = tep_db_prepare_input($HTTP_POST_VARS['username']);
  16. $password = tep_db_prepare_input($HTTP_POST_VARS['password']);
  17. $check_query = tep_db_query("select id from " . TABLE_ADMINISTRATORS . " where user_name = '" . tep_db_input($username) . "' limit 1");
  18. if (tep_db_num_rows($check_query) < 1) {
  19. tep_db_query("insert into " . TABLE_ADMINISTRATORS . " (user_name, user_password) values ('" . tep_db_input($username) . "', '" . tep_db_input(tep_encrypt_password($password)) . "')");
  20. } else {
  21. $messageStack->add_session(ERROR_ADMINISTRATOR_EXISTS, 'error');
  22. }
  23. tep_redirect(tep_href_link(FILENAME_ADMINISTRATORS));
  24. break;
  25. case 'save':
  26. require('includes/functions/password_funcs.php');
  27. $username = tep_db_prepare_input($HTTP_POST_VARS['username']);
  28. $password = tep_db_prepare_input($HTTP_POST_VARS['password']);
  29. $check_query = tep_db_query("select id from " . TABLE_ADMINISTRATORS . " where user_name = '" . tep_db_input($admin['username']) . "'");
  30. $check = tep_db_fetch_array($check_query);
  31. if ($admin['id'] == $check['id']) {
  32. $admin['username'] = $username;
  33. }
  34. tep_db_query("update " . TABLE_ADMINISTRATORS . " set user_name = '" . tep_db_input($username) . "' where id = '" . (int)$HTTP_GET_VARS['aID'] . "'");
  35. if (tep_not_null($password)) {
  36. tep_db_query("update " . TABLE_ADMINISTRATORS . " set user_password = '" . tep_db_input(tep_encrypt_password($password)) . "' where id = '" . (int)$HTTP_GET_VARS['aID'] . "'");
  37. }
  38. tep_redirect(tep_href_link(FILENAME_ADMINISTRATORS, 'aID=' . (int)$HTTP_GET_VARS['aID']));
  39. break;
  40. case 'deleteconfirm':
  41. $id = tep_db_prepare_input($HTTP_GET_VARS['aID']);
  42. $check_query = tep_db_query("select id from " . TABLE_ADMINISTRATORS . " where user_name = '" . tep_db_input($admin['username']) . "'");
  43. $check = tep_db_fetch_array($check_query);
  44. if ($id == $check['id']) {
  45. tep_session_unregister('admin');
  46. }
  47. tep_db_query("delete from " . TABLE_ADMINISTRATORS . " where id = '" . (int)$id . "'");
  48. tep_redirect(tep_href_link(FILENAME_ADMINISTRATORS));
  49. break;
  50. }
  51. }
  52. ?>
  53. <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
  54. <html <?php echo HTML_PARAMS; ?>>
  55. <head>
  56. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
  57. <title><?php echo TITLE; ?></title>
  58. <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
  59. <script language="javascript" src="includes/general.js"></script>
  60. </head>
  61. <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();">
  62. <!-- header //-->
  63. <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
  64. <!-- header_eof //-->
  65. <!-- body //-->
  66. <table border="0" width="100%" cellspacing="2" cellpadding="2">
  67. <tr>
  68. <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
  69. <!-- left_navigation //-->
  70. <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
  71. <!-- left_navigation_eof //-->
  72. </table></td>
  73. <!-- body_text //-->
  74. <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  75. <tr>
  76. <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  77. <tr>
  78. <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
  79. <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
  80. </tr>
  81. </table></td>
  82. </tr>
  83. <tr>
  84. <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  85. <tr>
  86. <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  87. <tr class="dataTableHeadingRow">
  88. <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_ADMINISTRATORS; ?></td>
  89. <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
  90. </tr>
  91. <?php
  92. $admins_query = tep_db_query("select id, user_name from " . TABLE_ADMINISTRATORS . " order by user_name");
  93. while ($admins = tep_db_fetch_array($admins_query)) {
  94. if ((!isset($HTTP_GET_VARS['aID']) || (isset($HTTP_GET_VARS['aID']) && ($HTTP_GET_VARS['aID'] == $admins['id']))) && !isset($aInfo) && (substr($action, 0, 3) != 'new')) {
  95. $aInfo = new objectInfo($admins);
  96. }
  97. if ( (isset($aInfo) && is_object($aInfo)) && ($admins['id'] == $aInfo->id) ) {
  98. echo ' <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_ADMINISTRATORS, 'aID=' . $aInfo->id . '&action=edit') . '\'">' . "\n";
  99. } else {
  100. echo ' <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_ADMINISTRATORS, 'aID=' . $admins['id']) . '\'">' . "\n";
  101. }
  102. ?>
  103. <td class="dataTableContent"><?php echo $admins['user_name']; ?></td>
  104. <td class="dataTableContent" align="right"><?php if ( (isset($aInfo) && is_object($aInfo)) && ($admins['id'] == $aInfo->id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_ADMINISTRATORS, 'aID=' . $admins['id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
  105. </tr>
  106. <?php
  107. }
  108. ?>
  109. <tr>
  110. <td colspan="2" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ADMINISTRATORS, 'action=new') . '">' . tep_image_button('button_insert.gif', IMAGE_INSERT) . '</a>'; ?></td>
  111. </tr>
  112. </table></td>
  113. <?php
  114. $heading = array();
  115. $contents = array();
  116. switch ($action) {
  117. case 'new':
  118. $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_ADMINISTRATOR . '</b>');
  119. $contents = array('form' => tep_draw_form('administrator', FILENAME_ADMINISTRATORS, 'action=insert'));
  120. $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);
  121. $contents[] = array('text' => '<br>' . TEXT_INFO_USERNAME . '<br>' . tep_draw_input_field('username'));
  122. $contents[] = array('text' => '<br>' . TEXT_INFO_PASSWORD . '<br>' . tep_draw_password_field('password'));
  123. $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . '&nbsp;<a href="' . tep_href_link(FILENAME_ADMINISTRATORS) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
  124. break;
  125. case 'edit':
  126. $heading[] = array('text' => '<b>' . $aInfo->user_name . '</b>');
  127. $contents = array('form' => tep_draw_form('administrator', FILENAME_ADMINISTRATORS, 'aID=' . $aInfo->id . '&action=save'));
  128. $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);
  129. $contents[] = array('text' => '<br>' . TEXT_INFO_USERNAME . '<br>' . tep_draw_input_field('username', $aInfo->user_name));
  130. $contents[] = array('text' => '<br>' . TEXT_INFO_NEW_PASSWORD . '<br>' . tep_draw_password_field('password'));
  131. $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_ADMINISTRATORS, 'aID=' . $aInfo->id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
  132. break;
  133. case 'delete':
  134. $heading[] = array('text' => '<b>' . $aInfo->user_name . '</b>');
  135. $contents = array('form' => tep_draw_form('administrator', FILENAME_ADMINISTRATORS, 'aID=' . $aInfo->id . '&action=deleteconfirm'));
  136. $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
  137. $contents[] = array('text' => '<br><b>' . $aInfo->user_name . '</b>');
  138. $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_ADMINISTRATORS, 'aID=' . $aInfo->id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
  139. break;
  140. default:
  141. if (isset($aInfo) && is_object($aInfo)) {
  142. $heading[] = array('text' => '<b>' . $aInfo->user_name . '</b>');
  143. $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_ADMINISTRATORS, 'aID=' . $aInfo->id . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_ADMINISTRATORS, 'aID=' . $aInfo->id . '&action=delete') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>');
  144. }
  145. break;
  146. }
  147. if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
  148. echo ' <td width="25%" valign="top">' . "\n";
  149. $box = new box;
  150. echo $box->infoBox($heading, $contents);
  151. echo ' </td>' . "\n";
  152. }
  153. ?>
  154. </tr>
  155. </table></td>
  156. </tr>
  157. </table></td>
  158. <!-- body_text_eof //-->
  159. </tr>
  160. </table>
  161. <!-- body_eof //-->
  162. <!-- footer //-->
  163. <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
  164. <!-- footer_eof //-->
  165. <br>
  166. </body>
  167. </html>
  168. <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>