public function delete_clinic(){ $app = JFactory::getApplication(); $user = JFactory::getUser(); $isRoot = $user->authorise('core.admin'); $input = $app->input; header('Content-Type: application/json'); //Only Authorised users can remove departments. if ($user->get('guest') == 1) { echo json_encode(array("success"=>false, 'message'=>'Вы должны авторизироваться.')); JFactory::getApplication()->close(); return; } //OK now get request parameters $clinicId = $input->getInt('clinicId'); //Check if department exists $clinic = Departments::getClinic($clinicId); if($clinic==null){ echo json_encode(array("success"=>false, 'message'=>'Такой клиники не существует.')); JFactory::getApplication()->close(); return; } //Now check if this user has access rights to perform this operation if(!($isRoot || $user->get('id')==$clinic->profile_id )){ echo json_encode(array("success"=>false, 'message'=>'У вас недостаточно прав для выполнения операции.')); JFactory::getApplication()->close(); return; } //OK now we can add user to department Departments::removeClinic($clinicId); $result = array('success'=>true, 'message'=>'Клиника удалена', 'departments'=>DepartmentsView::renderDepartments(Departments::getDepartments($clinic->profile_id),$clinic->profile_id,$user, $isRoot)); echo json_encode( $result ); JFactory::getApplication()->close(); }