public function indexJsonAction() { $mode = $this->_getParam('mode', ''); $this->view->mode = $mode; $user_id = getUserId(); if ($mode == "save-client") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); $allparam['user_id'] = $user_id; $result = $index->updateUser($allparam); } if ($mode == "save-password") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); $allparam['user_id'] = $user_id; $result = $index->getUserByPassword($allparam); if ($result['value']['num'] == 0) { $this->view->result = 'Incorrect old password'; return; } if ($allparam['new_password'] != $allparam['confirm_password']) { $this->view->result = 'New password and confirm password is not equal'; return; } if ($allparam['new_password'] == '') { $this->view->result = 'Write new password'; return; } $index->updatePassword($allparam); $this->view->result = 'Successfully changed'; } if ($mode == "delete-order") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); $result = $index->deleteOrder($allparam['order_id']); $this->view->result = 'Successfully deleted'; } if ($mode == "add-to-basket") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); $allparam['user_id'] = getUserId(); if (getUserId() == 0) { $this->view->result = 'You must login before making this purchase'; return; } $result = $index->checkCountProduct($allparam); if ($result['value'][0]['count'] < 1) { $this->view->result = 'This autopart is not already in shop'; return; } $result = $index->addOrder($allparam); $this->view->result = 'Successfully add to basket'; } if ($mode == "delete-autopart") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); $result = $index->deleteAutopart($allparam['autopart_id']); $this->view->result = 'Successfully deleted'; } if ($mode == "confirm-deliver") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); $result = $index->editOrderDelivered($allparam['order_id']); $this->view->result = 'Successfully changed'; } if ($mode == "get-model") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); $result = $index->getModelsByBrand($allparam['brand_id']); $this->view->result = $result['value']; } if ($mode == "login") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); if ($allparam['login'] == '' || $allparam['password'] == '') { $this->view->result = 'Please, fill the fields'; return; } $result = $index->getEmail($allparam); if ($result['value']['is_online'] == 1) { $this->view->result = "You can't sign in, because somebody is already authorized"; return; } if ($result['value']['num'] == 0) { $this->view->result = 'Incorrect password or email'; return; } else { $this->_helper->AjaxContext()->addActionContext('index-json', 'json')->initContext('json'); $login = $this->_getParam('login'); $password = $this->_getParam('password'); $api = new Api_Project(); $result = $api->setAuth($login, md5($password)); if ($result == true) { $index->updateOnline(); } $this->view->status = $result; } } if ($mode == "register") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); if ($allparam['login'] == '' || $allparam['password'] == '' || $allparam['address'] == '' || $allparam['phone'] == '') { $this->view->result = 'Please, fill the fields'; return; } if ($allparam['password'] != $allparam['password2']) { $this->view->result = 'Password and confirm password is not equal'; return; } $result = $index->addUser($allparam); $this->_helper->AjaxContext()->addActionContext('index-json', 'json')->initContext('json'); $login = $this->_getParam('login'); $password = $this->_getParam('password'); $api = new Api_Project(); $result = $api->setAuth($login, md5($password)); $this->view->status = $result; } if ($mode == "save-autopart") { $index = new Application_Model_DbTable_Index(); $allparam = $this->_getAllParams(); if ($allparam['autopart_id'] > 0) { $result = $index->editAutopart($allparam); } else { $result = $index->addAutopart($allparam); } } }