<?php
defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );

class Achievements_user extends MY_Controller {

  public function __construct()
  {
    parent::__construct();

    if( ! $this->zuser->is_logged_in ) r_s_jump( 'login' );
    check_action_authorization( 'achievements_user' );

    $this->load->model( 'Achievements_user_model' );

  }

  public function update($user_id)
  {

    $content = do_secure(post('content'));

    if( ! empty( $content ) )
    {
      $data = [
        'content' => $content,
        'update_at' => time(),
      ];
      
      $achievement = $this->Achievements_user_model->achievement( $user_id );
      
      if( empty( $achievement ) )
      {
        $data['user_id'] = $user_id;
        $data['is_show'] = true;

        $this->Achievements_user_model->add_data( $data );

        
        $data['id'] = $user_id;
        // add modal
        // $html = read_view( 'admin/responses/add_report', $data );

        $html = "";
        echo "Haha";
        r_success_add( $html, 'added');
      }

      $this->Achievements_user_model->update_data( $user_id, $data );

      $data['id'] = $user_id;
      // add modal
      // $html = read_view( 'admin/responses/add_report', $data );

      $html = "";
      echo "Haha";
      r_success_replace( $user_id, $html );
      // r_s_jump( 'admin/achievements_user', 'updated' );
    }
    
    r_error('err_content_cant_be_empty');
  }

}