<?php

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

class Announcement_per_user extends MY_Controller {

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

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

    $this->load->model( 'Announcement_per_user_model' );
  }

  public function update( $user_id )
  {
    
    $content = do_secure(post('content'));

    if( ! empty( $content ) )
    {
      $data = [
        "content" => $content,
        "update_at" => time()
      ];

      $announcement = $this->Announcement_per_user_model->announcement( $user_id );

      if( empty( $announcement ) )
      {
        $data['user_id'] = $user_id;
        $data['is_show'] = true;

        $id = $this->Announcement_per_user_model->add_data( $data );
        var_dump($id);
        // add modal
        // $html = read_view( 'admin/responses/add_report', $data );

        $html = "";
        r_success_add( $html );
      } else
      {

        $id = $this->Announcement_per_user_model->update_data( $user_id, $data );

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

        $html = "adsdasd";
        r_success_replace( $user_id, $html  );
      }

      r_error( 'err_content_cant_be_empty' );
    }

    r_error( 'err_content_cant_be_empty' );
  }
}