예제 #1
0
 /**
  * function to edit the custom field
  * @param object $evctl
  * @see popups/edit_custom_field_modal.php
  */
 public function eventEditCustomField(EventControler $evctl)
 {
     $idfields = (int) $evctl->idfields_ed;
     $update_data = false;
     if ($idfields > 0) {
         $this->getId($idfields);
         if ($this->getNumRows() > 0) {
             $update_data = true;
         } else {
             $update_data = false;
             $_SESSION["do_crm_messages"]->set_message('error', _('Record does not exit.'));
         }
     } else {
         $update_data = false;
         $_SESSION["do_crm_messages"]->set_message('error', _('Record does not exit.'));
     }
     if ($update_data === true) {
         $custom_field_type = $evctl->custom_field_type_ed;
         $req = $evctl->cf_req_ed;
         $field_validation = array();
         $is_required = false;
         if ($req == 'on') {
             $is_required = true;
             $field_validation["required"] = true;
         }
         switch ($custom_field_type) {
             case 1:
                 if ($is_required === true) {
                     if ($evctl->cf_max_len_ed != '' || (int) $evctl->cf_max_len_ed > 0) {
                         $field_validation["maxlength"] = (int) $evctl->cf_max_len_ed;
                     }
                     if ($evctl->cf_min_len_ed != '' || (int) $evctl->cf_min_len_ed > 0) {
                         $field_validation["minlength"] = (int) $evctl->cf_min_len_ed;
                     }
                 }
                 break;
             case 5:
                 $pick_values = $evctl->cf_pick_ed;
                 $not_equal = $evctl->cf_pick_notequal_ed;
                 if ($is_required === true) {
                     $field_validation["notEqual"] = $not_equal;
                 }
                 break;
             case 6:
                 $pick_values = $evctl->cf_pick_ed;
                 break;
         }
         if (count($field_validation) > 0) {
             $field_validation_entry = json_encode($field_validation);
         } else {
             $field_validation_entry = '';
         }
         $qry_update = "\n\t\t\tupdate " . $this->getTable() . " \n\t\t\tset `field_label` = ?,\n\t\t\t`field_validation` = ?\n\t\t\twhere idfields = ?";
         $this->query($qry_update, array(CommonUtils::purify_input($evctl->cf_label_ed), $field_validation_entry, $idfields));
         if ($custom_field_type == 5 || $custom_field_type == 6) {
             //$pick_values_seperated = explode(PHP_EOL,$evctl->cf_pick);
             $pick_values_seperated = preg_split('/[\\r\\n]+/', $evctl->cf_pick_ed, -1, PREG_SPLIT_NO_EMPTY);
             $do_combo_values = new ComboValues();
             $do_combo_values->update_combo_values($idfields, $pick_values_seperated);
         }
         $_SESSION["do_crm_messages"]->set_message('success', _('Custom field updated successfully !'));
     }
 }