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

/app/code/core/Mage/Adminhtml/controllers/IndexController.php

https://bitbucket.org/andrewjleavitt/magestudy
PHP | 233 lines | 170 code | 28 blank | 35 comment | 18 complexity | 1cb673183163bdf9e26943d3cb9c4f92 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Adminhtml
  23. * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. class Mage_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
  27. {
  28. protected function _outTemplate($tplName, $data=array())
  29. {
  30. $this->_initLayoutMessages('adminhtml/session');
  31. $block = $this->getLayout()->createBlock('adminhtml/template')->setTemplate("$tplName.phtml");
  32. foreach ($data as $index=>$value) {
  33. $block->assign($index, $value);
  34. }
  35. $html = $block->toHtml();
  36. Mage::getSingleton('core/translate_inline')->processResponseBody($html);
  37. $this->getResponse()->setBody($html);
  38. }
  39. /**
  40. * Admin area entry point
  41. * Always redirects to the startup page url
  42. */
  43. public function indexAction()
  44. {
  45. $session = Mage::getSingleton('admin/session');
  46. $url = $session->getUser()->getStartupPageUrl();
  47. if ($session->isFirstPageAfterLogin()) {
  48. // retain the "first page after login" value in session (before redirect)
  49. $session->setIsFirstPageAfterLogin(true);
  50. }
  51. $this->_redirect($url);
  52. }
  53. public function loginAction()
  54. {
  55. if (Mage::getSingleton('admin/session')->isLoggedIn()) {
  56. $this->_redirect('*');
  57. return;
  58. }
  59. $loginData = $this->getRequest()->getParam('login');
  60. $data = array();
  61. if( is_array($loginData) && array_key_exists('username', $loginData) ) {
  62. $data['username'] = $loginData['username'];
  63. } else {
  64. $data['username'] = null;
  65. }
  66. $this->_outTemplate('login', $data);
  67. }
  68. public function logoutAction()
  69. {
  70. /** @var $adminSession Mage_Admin_Model_Session */
  71. $adminSession = Mage::getSingleton('admin/session');
  72. $adminSession->unsetAll();
  73. $adminSession->getCookie()->delete($adminSession->getSessionName());
  74. $adminSession->addSuccess(Mage::helper('adminhtml')->__('You have logged out.'));
  75. $this->_redirect('*');
  76. }
  77. /**
  78. * Global Search Action
  79. *
  80. */
  81. public function globalSearchAction()
  82. {
  83. $searchModules = Mage::getConfig()->getNode("adminhtml/global_search");
  84. $items = array();
  85. if ( !Mage::getSingleton('admin/session')->isAllowed('admin/global_search') ) {
  86. $items[] = array(
  87. 'id' => 'error',
  88. 'type' => Mage::helper('adminhtml')->__('Error'),
  89. 'name' => Mage::helper('adminhtml')->__('Access Denied'),
  90. 'description' => Mage::helper('adminhtml')->__('You have not enough permissions to use this functionality.')
  91. );
  92. $totalCount = 1;
  93. } else {
  94. if (empty($searchModules)) {
  95. $items[] = array(
  96. 'id' => 'error',
  97. 'type' => Mage::helper('adminhtml')->__('Error'),
  98. 'name' => Mage::helper('adminhtml')->__('No search modules were registered'),
  99. 'description' => Mage::helper('adminhtml')->__('Please make sure that all global admin search modules are installed and activated.')
  100. );
  101. $totalCount = 1;
  102. } else {
  103. $start = $this->getRequest()->getParam('start', 1);
  104. $limit = $this->getRequest()->getParam('limit', 10);
  105. $query = $this->getRequest()->getParam('query', '');
  106. foreach ($searchModules->children() as $searchConfig) {
  107. if ($searchConfig->acl && !Mage::getSingleton('admin/session')->isAllowed($searchConfig->acl)){
  108. continue;
  109. }
  110. $className = $searchConfig->getClassName();
  111. if (empty($className)) {
  112. continue;
  113. }
  114. $searchInstance = new $className();
  115. $results = $searchInstance->setStart($start)
  116. ->setLimit($limit)
  117. ->setQuery($query)
  118. ->load()
  119. ->getResults();
  120. $items = array_merge_recursive($items, $results);
  121. }
  122. $totalCount = sizeof($items);
  123. }
  124. }
  125. $block = $this->getLayout()->createBlock('adminhtml/template')
  126. ->setTemplate('system/autocomplete.phtml')
  127. ->assign('items', $items);
  128. $this->getResponse()->setBody($block->toHtml());
  129. }
  130. public function exampleAction()
  131. {
  132. $this->_outTemplate('example');
  133. }
  134. public function testAction()
  135. {
  136. echo $this->getLayout()->createBlock('core/profiler')->toHtml();
  137. }
  138. public function changeLocaleAction()
  139. {
  140. $locale = $this->getRequest()->getParam('locale');
  141. if ($locale) {
  142. Mage::getSingleton('adminhtml/session')->setLocale($locale);
  143. }
  144. $this->_redirectReferer();
  145. }
  146. public function deniedJsonAction()
  147. {
  148. $this->getResponse()->setBody($this->_getDeniedJson());
  149. }
  150. protected function _getDeniedJson()
  151. {
  152. return Mage::helper('core')->jsonEncode(
  153. array(
  154. 'ajaxExpired' => 1,
  155. 'ajaxRedirect' => $this->getUrl('*/index/login')
  156. )
  157. );
  158. }
  159. public function deniedIframeAction()
  160. {
  161. $this->getResponse()->setBody($this->_getDeniedIframe());
  162. }
  163. protected function _getDeniedIframe()
  164. {
  165. return '<script type="text/javascript">parent.window.location = \''.$this->getUrl('*/index/login').'\';</script>';
  166. }
  167. public function forgotpasswordAction()
  168. {
  169. $email = $this->getRequest()->getParam('email');
  170. $params = $this->getRequest()->getParams();
  171. if (!empty($email) && !empty($params)) {
  172. $collection = Mage::getResourceModel('admin/user_collection');
  173. /* @var $collection Mage_Admin_Model_Mysql4_User_Collection */
  174. $collection->addFieldToFilter('email', $email);
  175. $collection->load(false);
  176. if ($collection->getSize() > 0) {
  177. foreach ($collection as $item) {
  178. $user = Mage::getModel('admin/user')->load($item->getId());
  179. if ($user->getId()) {
  180. $pass = Mage::helper('core')->getRandomString(7);
  181. $user->setPassword($pass);
  182. $user->save();
  183. $user->setPlainPassword($pass);
  184. $user->sendNewPasswordEmail();
  185. Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('A new password was sent to your email address. Please check your email and click Back to Login.'));
  186. $email = '';
  187. }
  188. break;
  189. }
  190. } else {
  191. Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Cannot find the email address.'));
  192. }
  193. } elseif (!empty($params)) {
  194. Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('The email address is empty.'));
  195. }
  196. $data = array(
  197. 'email' => $email
  198. );
  199. $this->_outTemplate('forgotpassword', $data);
  200. }
  201. protected function _isAllowed()
  202. {
  203. return true;
  204. }
  205. }