/**
  * event function to add a custom view
  * @param object $evctl
  * @return void
  */
 public function eventAddRecord(EventControler $evctl)
 {
     if (trim($evctl->cvname) == '') {
         $_SESSION["do_crm_messages"]->set_message('error', _('Please add a custom view name before saving !'));
         $next_page = NavigationControl::getNavigationLink("CustomView", "add");
         $dis = new Display($next_page);
         $dis->addParam("target_module_id", (int) $evctl->target_module_id);
         $evctl->setDisplayNext($dis);
     } elseif ((int) $evctl->target_module_id == 0) {
         $_SESSION["do_crm_messages"]->set_message('error', _('Missing target module for custom view !'));
         $next_page = NavigationControl::getNavigationLink("CustomView", "add");
         $dis = new Display($next_page);
         $evctl->setDisplayNext($dis);
     } elseif (false === $_SESSION["do_crm_action_permission"]->action_permitted('add', 17)) {
         $_SESSION["do_crm_messages"]->set_message('error', _('You do not have permission to add record !'));
         $next_page = NavigationControl::getNavigationLink($_SESSION["do_module"]->modules_full_details[$evctl->target_module_id]["name"], "list");
         $dis = new Display($next_page);
         $evctl->setDisplayNext($dis);
     } else {
         $this->addNew();
         $this->name = $evctl->cvname;
         $this->iduser = $_SESSION["do_user"]->iduser;
         $this->is_default = $evctl->is_default == 'on' ? 1 : 0;
         if ($_SESSION["do_user"]->is_admin == 1) {
             $this->is_public = $evctl->is_public == 'on' ? 1 : 0;
         }
         $this->idmodule = (int) $evctl->target_module_id;
         $this->is_editable = 1;
         $this->add();
         $idcustom_view = $this->getInsertId();
         //reset default custom view if is_default is set
         if ($evctl->is_default == 'on') {
             $this->reset_default_custom_view($idcustom_view, $evctl->target_module_id);
         }
         //add custom view fields
         $do_custom_view_fields = new CustomViewFields();
         $do_custom_view_fields->add_custom_view_fields($idcustom_view, $evctl->cv_fields);
         //add custom view filter
         $do_custom_view_filter = new CustomViewFilter();
         $do_custom_view_filter->add_custom_view_date_filter($idcustom_view, $evctl->cv_date_field, $evctl->cv_date_field_type, $evctl->cv_date_start, $evctl->cv_date_end);
         //add advanced filter
         $adv_filter_data = array("cv_adv_fields_1" => $evctl->cv_adv_fields_1, "cv_adv_fields_type_1" => $evctl->cv_adv_fields_type_1, "cv_adv_fields_val_1" => $_POST["cv_adv_fields_val_1"], "cv_adv_fields_2" => $evctl->cv_adv_fields_2, "cv_adv_fields_type_2" => $evctl->cv_adv_fields_type_2, "cv_adv_fields_val_2" => $_POST["cv_adv_fields_val_2"], "cv_adv_fields_3" => $evctl->cv_adv_fields_3, "cv_adv_fields_type_3" => $evctl->cv_adv_fields_type_3, "cv_adv_fields_val_3" => $_POST["cv_adv_fields_val_3"], "cv_adv_fields_4" => $evctl->cv_adv_fields_4, "cv_adv_fields_type_4" => $evctl->cv_adv_fields_type_4, "cv_adv_fields_val_4" => $_POST["cv_adv_fields_val_4"], "cv_adv_fields_5" => $evctl->cv_adv_fields_5, "cv_adv_fields_type_5" => $evctl->cv_adv_fields_type_5, "cv_adv_fields_val_5" => $_POST["cv_adv_fields_val_5"]);
         $do_custom_view_filter->add_custom_view_adv_filter($idcustom_view, $adv_filter_data);
         //redirect after adding the custom view
         $next_page = NavigationControl::getNavigationLink($_SESSION["do_module"]->modules_full_details[$evctl->target_module_id]["name"], "list", '', '&custom_view_id=' . $idcustom_view);
         $dis = new Display($next_page);
         $evctl->setDisplayNext($dis);
     }
 }