コード例 #1
0
   \t<input type='hidden' name='action' value='ImportCustomFieldStructure'>
   {$mod_strings['LBL_IMPORT_CUSTOM_FIELDS_STRUCT']}: <input name="sugfile" type="file" />
    <input type="submit" value="{$mod_strings['LBL_ICF_IMPORT_S']}" class='button'/>
</form>
EOQ;
} else {
    $fmd = new FieldsMetaData();
    echo $mod_strings['LBL_ICF_DROPPING'] . '<br>';
    $lines = file($_FILES['sugfile']['tmp_name']);
    $cur = array();
    foreach ($lines as $line) {
        if (trim($line) == 'DONE') {
            $fmd->new_with_id = true;
            echo 'Adding:' . $fmd->custom_module . '-' . $fmd->name . '<br>';
            $fmd->db->query("DELETE FROM {$fmd->table_name} WHERE id='{$fmd->id}'");
            $fmd->save(false);
            $fmd = new FieldsMetaData();
        } else {
            $ln = explode(':::', $line, 2);
            if (sizeof($ln) == 2) {
                $KEY = trim($ln[0]);
                $fmd->{$KEY} = trim($ln[1]);
            }
        }
    }
    $_REQUEST['run'] = true;
    $result = $fmd->db->query("SELECT count(*) field_count FROM {$fmd->table_name}");
    $row = $fmd->db->fetchByAssoc($result);
    echo 'Total Custom Fields :' . $row['field_count'] . '<br>';
    include 'modules/Administration/UpgradeFields.php';
}
コード例 #2
0
 /**
  * Adds a custom field using a field object
  *
  * @param Field Object $field
  * @return boolean
  */
 function addFieldObject(&$field)
 {
     Log::debug('adding field');
     $object_name = $this->module;
     $db_name = $field->name;
     $fmd = new FieldsMetaData();
     $id = $fmd->retrieve($object_name . $db_name, true, false);
     $is_update = false;
     $label = strtoupper($field->label);
     if (!empty($id)) {
         $is_update = true;
     } else {
         $db_name = $this->getDBName($field->name);
         $field->name = $db_name;
     }
     $this->createCustomTable();
     $fmd->id = $object_name . $db_name;
     $fmd->custom_module = $object_name;
     $fmd->name = $db_name;
     $fmd->vname = $label;
     $fmd->type = $field->type;
     $fmd->help = $field->help;
     if (!empty($field->len)) {
         $fmd->len = $field->len;
     }
     // tyoung bug 15407 - was being set to $field->size so changes weren't being saved
     $fmd->required = $field->required ? 1 : 0;
     $fmd->default_value = $field->default;
     $fmd->ext1 = $field->ext1;
     $fmd->ext2 = $field->ext2;
     $fmd->ext3 = $field->ext3;
     $fmd->ext4 = isset($field->ext4) ? $field->ext4 : '';
     $fmd->comments = $field->comment;
     $fmd->massupdate = $field->massupdate;
     $fmd->importable = isset($field->importable) ? $field->importable : null;
     $fmd->duplicate_merge = $field->duplicate_merge;
     $fmd->audited = $field->audited;
     $fmd->reportable = $field->reportable ? 1 : 0;
     if (!$is_update) {
         $fmd->new_with_id = true;
     }
     if ($field) {
         if (!$is_update) {
             //Do two SQL calls here in this case
             //The first is to create the column in the custom table without the default value
             //The second is to modify the column created in the custom table to set the default value
             //We do this so that the existing entries in the custom table don't have the default value set
             $field->default = '';
             $field->default_value = '';
             // resetting default and default_value does not work for multienum and causes trouble for mssql
             // so using a temporary variable here to indicate that we don't want default for this query
             $field->no_default = 1;
             $query = $field->get_db_add_alter_table($this->bean->table_name . '_cstm');
             // unsetting temporary member variable
             unset($field->no_default);
             if (!empty($query)) {
                 $GLOBALS['db']->query($query, true, "Cannot create column");
                 $field->default = $fmd->default_value;
                 $field->default_value = $fmd->default_value;
                 $query = $field->get_db_modify_alter_table($this->bean->table_name . '_cstm');
                 if (!empty($query)) {
                     $GLOBALS['db']->query($query, true, "Cannot set default");
                 }
             }
         } else {
             $query = $field->get_db_modify_alter_table($this->bean->table_name . '_cstm');
             if (!empty($query)) {
                 $GLOBALS['db']->query($query, true, "Cannot modify field");
             }
         }
         $fmd->save();
         $this->buildCache($this->module);
         $this->saveExtendedAttributes($field, array_keys($fmd->field_defs));
     }
     return true;
 }
コード例 #3
0
 * Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.;
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 */
require_once 'modules/EditCustomFields/FieldsMetaData.php';
require_once 'modules/EditCustomFields/CustomFieldsTableSchema.php';
$fields_meta_data = new FieldsMetaData();
////
//// save the metadata to the fields_meta_data table
////
foreach ($fields_meta_data->column_fields as $field) {
    if (isset($_REQUEST[$field])) {
        $fields_meta_data->{$field} = $_REQUEST[$field];
    }
}
$fields_meta_data->save();
////
//// create/modify the custom field table
////
$new_field = empty($_REQUEST['id']);
$new_field = true;
$custom_table_name = strtolower($fields_meta_data->custom_module) . '_cstm';
$custom_fields_table_schema = new CustomFieldsTableSchema($custom_table_name);
if (!CustomFieldsTableSchema::custom_table_exists($custom_table_name)) {
    $custom_fields_table_schema->create_table();
}
$column_name = $fields_meta_data->name;
$field_label = $fields_meta_data->label;
$data_type = $fields_meta_data->data_type;
$max_size = $fields_meta_data->max_size;
$required = $fields_meta_data->required_option;
コード例 #4
0
 /**
  * Adds a custom field using a field object
  *
  * @param Field Object $field
  * @return boolean
  */
 function addFieldObject(&$field)
 {
     $GLOBALS['log']->debug('adding field');
     $object_name = $this->module;
     $db_name = $field->name;
     $fmd = new FieldsMetaData();
     $id = $fmd->retrieve($object_name . $db_name, true, false);
     $is_update = false;
     $label = $field->label;
     if (!empty($id)) {
         $is_update = true;
     } else {
         $db_name = $this->getDBName($field->name);
         $field->name = $db_name;
     }
     $this->createCustomTable();
     $fmd->id = $object_name . $db_name;
     $fmd->custom_module = $object_name;
     $fmd->name = $db_name;
     $fmd->vname = $label;
     $fmd->type = $field->type;
     $fmd->help = $field->help;
     $fmd->len = $field->len;
     // tyoung bug 15407 - was being set to $field->size so changes weren't being saved
     $fmd->required = $field->required ? 1 : 0;
     $fmd->default_value = $field->default;
     $fmd->ext1 = $field->ext1;
     $fmd->ext2 = $field->ext2;
     $fmd->ext3 = $field->ext3;
     $fmd->ext4 = isset($field->ext4) ? $field->ext4 : '';
     $fmd->comments = $field->comment;
     $fmd->massupdate = $field->massupdate;
     $fmd->importable = isset($field->importable) ? $field->importable : null;
     $fmd->duplicate_merge = $field->duplicate_merge;
     $fmd->audited = $field->audited;
     $fmd->reportable = $field->reportable ? 1 : 0;
     if (!$is_update) {
         $fmd->new_with_id = true;
     }
     $fmd->save();
     $this->buildCache($this->module);
     if ($field) {
         if (!$is_update) {
             $query = $field->get_db_add_alter_table($this->bean->table_name . '_cstm');
         } else {
             $query = $field->get_db_modify_alter_table($this->bean->table_name . '_cstm');
         }
         if (!empty($query)) {
             $GLOBALS['db']->query($query);
         }
     }
     return true;
 }
コード例 #5
0
 function addField($name, $label = '', $type = 'Text', $max_size = '255', $required_option = 'optional', $default_value = '', $ext1 = '', $ext2 = '', $ext3 = '', $audited = 0, $mass_update = 0, $ext4 = '', $help = '', $duplicate_merge = 0)
 {
     if (empty($label)) {
         $label = $name;
     }
     $label = $this->addLabel($label);
     $object_name = $this->module;
     $db_name = $this->getDBName($name);
     if (isset($this->avail_fields[$db_name])) {
         return;
     }
     if (!array_key_exists($this->module, $this->modules)) {
         $this->createCustomTable();
     }
     require_once 'modules/EditCustomFields/FieldsMetaData.php';
     $fmd = new FieldsMetaData();
     $fmd->id = $object_name . $db_name;
     $fmd->custom_module = $object_name;
     $fmd->name = $db_name;
     $fmd->label = $label;
     $fmd->data_type = $type;
     $fmd->max_size = $max_size;
     $fmd->required_option = $required_option;
     $fmd->default_value = $default_value;
     $fmd->ext1 = $ext1;
     $fmd->ext2 = $ext2;
     $fmd->ext3 = $ext3;
     $fmd->ext4 = $ext4;
     $fmd->help = $help;
     $fmd->mass_update = $mass_update;
     $fmd->duplicate_merge = $duplicate_merge;
     $fmd->audited = $audited;
     $fmd->new_with_id = true;
     $fmd->save();
     $this->cleanSaveToCache();
     if (!array_key_exists($this->module, $this->modules)) {
         $this->createCustomTable();
         $this->saveCustomModulesList();
     }
     $this->avail_fields = array();
     $this->getAvailableFields(true);
     $field = $this->getField($name);
     if ($field) {
         $query = $field->get_db_add_alter_table($this->bean->table_name . '_cstm');
         if (!empty($query)) {
             $this->db->query($query);
         }
     }
 }