00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
00029 {
00030 protected function _outTemplate($tplName, $data=array())
00031 {
00032 $this->_initLayoutMessages('adminhtml/session');
00033 $block = $this->getLayout()->createBlock('adminhtml/template')->setTemplate("$tplName.phtml");
00034 foreach ($data as $index=>$value) {
00035 $block->assign($index, $value);
00036 }
00037 $this->getResponse()->setBody($block->toHtml());
00038 }
00039
00040 public function indexAction()
00041 {
00042 $url = Mage::getSingleton('admin/session')->getUser()->getStartupPageUrl();
00043
00044 $this->_redirect($url);
00045 return;
00046
00047 $this->loadLayout();
00048 $block = $this->getLayout()->createBlock('adminhtml/template', 'system.info')
00049 ->setTemplate('system/info.phtml');
00050
00051 $this->_addContent($block);
00052
00053 $this->renderLayout();
00054 }
00055
00056 public function loginAction()
00057 {
00058 if (Mage::getSingleton('admin/session')->isLoggedIn()) {
00059 $this->_redirect('*');
00060 return;
00061 }
00062 $loginData = $this->getRequest()->getParam('login');
00063 $data = array();
00064
00065 if( is_array($loginData) && array_key_exists('username', $loginData) ) {
00066 $data['username'] = $loginData['username'];
00067 } else {
00068 $data['username'] = null;
00069 }
00070 #print_r($data);
00071 $this->_outTemplate('login', $data);
00072 }
00073
00074 public function logoutAction()
00075 {
00076 $auth = Mage::getSingleton('admin/session')->unsetAll();
00077 Mage::getSingleton('adminhtml/session')->unsetAll();
00078 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('You successfully logged out.'));
00079 $this->_redirect('*');
00080 }
00081
00082 public function globalSearchAction()
00083 {
00084 $searchModules = Mage::getConfig()->getNode("adminhtml/global_search");
00085 $items = array();
00086
00087 if ( !Mage::getSingleton('admin/session')->isAllowed('admin/global_search') ) {
00088 $items[] = array(
00089 'id'=>'error',
00090 'type'=>'Error',
00091 'name'=>Mage::helper('adminhtml')->__('Access Deny'),
00092 'description'=>Mage::helper('adminhtml')->__('You have not enought permissions to use this functionality.')
00093 );
00094 $totalCount = 1;
00095 } else {
00096 if (empty($searchModules)) {
00097 $items[] = array('id'=>'error', 'type'=>'Error', 'name'=>Mage::helper('adminhtml')->__('No search modules registered'), 'description'=>Mage::helper('adminhtml')->__('Please make sure that all global admin search modules are installed and activated.'));
00098 $totalCount = 1;
00099 } else {
00100 $start = $this->getRequest()->getParam('start', 1);
00101 $limit = $this->getRequest()->getParam('limit', 10);
00102 $query = $this->getRequest()->getParam('query', '');
00103 foreach ($searchModules->children() as $searchConfig) {
00104 $className = $searchConfig->getClassName();
00105 if (empty($className)) {
00106 continue;
00107 }
00108 $searchInstance = new $className();
00109 $results = $searchInstance->setStart($start)->setLimit($limit)->setQuery($query)->load()->getResults();
00110 $items = array_merge_recursive($items, $results);
00111 }
00112 $totalCount = sizeof($items);
00113 }
00114 }
00115
00116 $block = $this->getLayout()->createBlock('adminhtml/template')
00117 ->setTemplate('system/autocomplete.phtml')
00118 ->assign('items', $items);
00119
00120 $this->getResponse()->setBody($block->toHtml());
00121 }
00122
00123 public function exampleAction()
00124 {
00125 $this->_outTemplate('example');
00126 }
00127
00128 public function testAction()
00129 {
00130 echo $this->getLayout()->createBlock('core/profiler')->toHtml();
00131 }
00132
00133 public function changeLocaleAction()
00134 {
00135 $locale = $this->getRequest()->getParam('locale');
00136 if ($locale) {
00137 Mage::getSingleton('adminhtml/session')->setLocale($locale);
00138 }
00139 $this->_redirectReferer();
00140 }
00141
00142 public function deniedJsonAction()
00143 {
00144 $this->getResponse()->setBody($this->_getDeniedJson());
00145 }
00146
00147 protected function _getDeniedJson()
00148 {
00149 return Zend_Json::encode(
00150 array(
00151 'ajaxExpired' => 1,
00152 'ajaxRedirect' => $this->getUrl('*/index/login')
00153 )
00154 );
00155 }
00156
00157 public function deniedIframeAction()
00158 {
00159 $this->getResponse()->setBody($this->_getDeniedIframe());
00160 }
00161
00162 protected function _getDeniedIframe()
00163 {
00164 return '<script type="text/javascript">parent.window.location = \''.$this->getUrl('*/index/login').'\';</script>';
00165 }
00166
00167 public function forgotpasswordAction ()
00168 {
00169 $email = $this->getRequest()->getParam('email');
00170 $params = $this->getRequest()->getParams();
00171 if (!empty($email) && !empty($params)) {
00172 $collection = Mage::getResourceModel('admin/user_collection');
00173 /* @var $collection Mage_Admin_Model_Mysql4_User_Collection */
00174 $collection->addFieldToFilter('email', $email);
00175 $collection->load(false);
00176
00177 if ($collection->getSize() > 0) {
00178 foreach ($collection as $item) {
00179 $user = Mage::getModel('admin/user')->load($item->getId());
00180 if ($user->getId()) {
00181 $pass = substr(md5(uniqid(rand(), true)), 0, 7);
00182 $user->setPassword($pass);
00183 $user->save();
00184 $user->setPlainPassword($pass);
00185 $user->sendNewPasswordEmail();
00186 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.'));
00187 $email = '';
00188 }
00189 break;
00190 }
00191 } else {
00192 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Can\'t find email address.'));
00193 }
00194 } elseif (!empty($params)) {
00195 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Email address is empty.'));
00196 }
00197
00198
00199 $data = array(
00200 'email' => $email
00201 );
00202 $this->_outTemplate('forgotpassword', $data);
00203 }
00204
00205
00206 protected function _isAllowed()
00207 {
00208
00209
00210
00211
00212
00213
00214
00215
00216 return true;
00217 }
00218 }