Ejemplo n.º 1
0
	/**
	 * Show the form so that the user can send the link to someone.
	 *
	 * @return  void
	 *
	 * @since 1.5
	 */
  public function add_clinic()
  {
    $app = JFactory::getApplication();
    $db = JFactory::getDbo();
    $user = JFactory::getUser();
    $isRoot = $user->authorise('core.admin');

    // JInput object
    $input = $app->input;
    header('Content-Type: application/json');

    //Only Authorised users can add departments.
    if ($user->get('guest') == 1)
    {
      echo json_encode(array("success"=>false, 'message'=>'Вы должны авторизироваться.'));
      JFactory::getApplication()->close();
      return;
    }

    $clinicName = $_POST['clinicName'];
    $clinicUrl = $_POST['clinicUrl'];
    $profileId = $input->getInt('profileId');


    if(!( $user->get('id')==$profileId || $isRoot)){
      echo json_encode(array("success"=>false, 'message'=>'У вас нет прав добавлять клиники данному профайлу.'));
      JFactory::getApplication()->close();
      return;
    }

    if($clinicName){
      $db->setQuery("SELECT 1 FROM #__comprofiler_plugin_department_clinic
                     WHERE title=".$db->quote($clinicName)."
                       AND profile_id=".$db->quote($profileId));
      if($db->loadResult()=="1"){
        echo json_encode(array("success"=>false, 'message'=>'Клиника с именем '.$clinicName.' уже существует.'));
        JFactory::getApplication()->close();
        return;
      }
    }

    Departments::addClinic($clinicName, $profileId, $clinicUrl);

    $result = array('success'=>true,'message'=>'Клиника добавлена', 'departments'=>
      DepartmentsView::renderDepartments(Departments::getDepartments($profileId),$profileId,$user, $isRoot));
    echo json_encode( $result );
    JFactory::getApplication()->close();
  }