示例#1
0
  public function delete(){
    $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
    $departmentId = $input->getInt('departmentId');

    //Check if department exists
    $department = Departments::getDepartment($departmentId);
    if($department==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')==$department->profile_id )){
      echo json_encode(array("success"=>false, 'message'=>'У вас недостаточно прав для выполнения операции.'));
      JFactory::getApplication()->close();
      return;
    }

    //OK now we can add user to department

    Departments::removeDepartment($departmentId);

    $result = array('success'=>true,
      'message'=>'Отделение удалено',
      'departments'=>DepartmentsView::renderDepartments(Departments::getDepartments($department->profile_id),$department->profile_id,$user, $isRoot));
    echo json_encode( $result );
    JFactory::getApplication()->close();
  }