Ejemplo n.º 1
0
// Initialization field name, field types
if (!isset($isSys)) {
    $isSys = 0;
}
if (isset($ClassID)) {
    $Id = $ClassID;
}
if (isset($SystemTableID) && $SystemTableID) {
    $Id = $SystemTableID;
}
if (isset($widgetclass_id) && $widgetclass_id) {
    $Id = $widgetclass_id;
    $isWidget = 1;
}
if (!isset($Id)) {
    $Id = $isSys ? GetSystemTableIDByFieldID($FieldID) : GetClassIDByFieldID($FieldID);
}
if ($isSys) {
    $main_section = "settings";
    $item_id = 1;
    $Title1 = "<a href=\"" . $ADMIN_PATH . "field/system.php\">" . SECTION_SECTIONS_OPTIONS_SYSTEM . "</a>";
    $Title2 = CONTROL_FIELD_FIELDS . " (" . GetSystemTableRusName($SystemTableID ? $SystemTableID : $Id) . ")";
    $Title3 = "<a href=\"" . $ADMIN_PATH . "field/systemField.php?SystemTableID=" . $SystemTableID . "\">" . CONTROL_FIELD_FIELDS . " (" . GetSystemTableRusName($SystemTableID ? $SystemTableID : $Id) . ")</a>";
    $DocPath = "http://" . $DOC_DOMAIN . "/settings/systables/fields/";
} else {
    $main_section = "control";
    $item_id = 8;
    $Title1 = "<a href=\"" . $ADMIN_PATH . "class/\">" . CONTROL_CLASS . "</a>";
    $Title2 = CONTROL_FIELD_FIELDS . " (" . GetClassNameByID($ClassID) . ")";
    $Title3 = "<a href=\"" . $ADMIN_PATH . "field/?ClassID=" . $ClassID . "\">" . CONTROL_FIELD_FIELDS . " (" . GetClassNameByID($ClassID) . ")</a>";
    $DocPath = "http://" . $DOC_DOMAIN . "/management/class/fields/";
Ejemplo n.º 2
0
/**
 * Insert into DB properties of field
 *
 * @param bool is field in system table
 * @return int field id ,0 -  unknown error, -1 = incorrect field name, -2 = field name is mysql_keyword, -3 = field already exits
 *                                           -4 = incorrect field format
 *
 */
function FieldCompleted()
{
    global $db;
    global $ClassID, $SystemTableID, $widgetclass_id;
    global $Inheritance, $DoSearch, $InTableView;
    global $FieldID, $FieldName, $Description, $TypeOfData_ID, $TypeOfEdit_ID, $Format, $Format_String, $Format_FS, $Extension, $NotNull, $Priority, $DefaultState, $attachment, $download;
    global $format_height, $format_width, $format_html, $format_br, $format_fck, $format_panel, $format_typo, $format_bbcode, $use_calendar, $protect_email, $use_transliteration, $transliteration_field, $use_url_rules;
    global $isSys, $widgetclass_id;
    $nc_core = nc_Core::get_object();
    $input = $nc_core->input;
    $ClassID = intval($ClassID);
    $FieldID = intval($FieldID);
    if ($TypeOfData_ID == 1) {
        $Format = $Format_String;
    }
    if ($FieldID) {
        $TableName = $isSys ? GetSystemTableName(GetSystemTableIDByFieldID($FieldID)) : "Message" . GetClassIDByFieldID($FieldID);
    } else {
        $TableName = $isSys ? GetSystemTableName($SystemTableID) : "Message" . $ClassID;
    }
    // widgets
    $widgetclass_id += 0;
    if ($FieldID) {
        $widgetclass_id = $db->get_var("SELECT `Widget_Class_ID` FROM `Field` WHERE `Field_ID`= '" . $FieldID . "'");
    }
    $NotNull += 0;
    $DoSearch += 0;
    $InTableView += 0;
    $Inheritance += 0;
    $Priority += 0;
    $format_height += 0;
    $format_width += 0;
    $format_html += 0;
    $format_br += 0;
    $format_fck += 0;
    $format_panel += 0;
    $format_typo += 0;
    $format_bbcode += 0;
    $format_use_resize = (int) $input->fetch_post('format_use_resize');
    $format_resize_width = (int) $input->fetch_post('format_resize_width');
    $format_resize_height = (int) $input->fetch_post('format_resize_height');
    $format_use_crop = (int) $input->fetch_post('format_use_crop');
    $format_crop_x0 = (int) $input->fetch_post('format_crop_x0');
    $format_crop_y0 = (int) $input->fetch_post('format_crop_y0');
    $format_crop_x1 = (int) $input->fetch_post('format_crop_x1');
    $format_crop_y1 = (int) $input->fetch_post('format_crop_y1');
    $format_crop_ignore = (int) $input->fetch_post('format_crop_ignore');
    $format_crop_ignore_width = (int) $input->fetch_post('format_crop_ignore_width');
    $format_crop_ignore_height = (int) $input->fetch_post('format_crop_ignore_height');
    $format_use_preview = (int) $input->fetch_post('format_use_preview');
    $format_preview_width = (int) $input->fetch_post('format_preview_width');
    $format_preview_height = (int) $input->fetch_post('format_preview_height');
    $use_calendar += 0;
    // float field
    if ($TypeOfData_ID == 7) {
        $DefaultState = str_replace(",", ".", $DefaultState);
    }
    $FieldName = str_replace(' ', '', $FieldName);
    if (!isCorrectFormat($Format, $TypeOfData_ID)) {
        return -4;
    }
    if (nc_is_mysql_keyword($FieldName)) {
        return -2;
    }
    // Добавим к Формату тип файловой системы\ настройки textarea
    if ($TypeOfData_ID == NC_FIELDTYPE_FILE) {
        if (!$Format_FS) {
            $Format_FS = NC_FS_SIMPLE;
        }
        $Format .= ":fs" . $Format_FS;
        $Format .= ":" . ($attachment ? 'attachment' : 'inline');
        $Format .= $download ? ':download' : '';
        if (nc_substr($Format, 0, 1) == ':') {
            $Format = nc_substr($Format, 1);
        }
        $Format .= ";";
        $Format .= "use_resize:" . $format_use_resize . ";";
        $Format .= "resize_width:" . $format_resize_width . ";";
        $Format .= "resize_height:" . $format_resize_height . ";";
        $Format .= "use_crop:" . $format_use_crop . ";";
        $Format .= "crop_x0:" . $format_crop_x0 . ";";
        $Format .= "crop_y0:" . $format_crop_y0 . ";";
        $Format .= "crop_x1:" . $format_crop_x1 . ";";
        $Format .= "crop_y1:" . $format_crop_y1 . ";";
        $Format .= "crop_ignore:" . $format_crop_ignore . ";";
        $Format .= "crop_ignore_width:" . $format_crop_ignore_width . ";";
        $Format .= "crop_ignore_height:" . $format_crop_ignore_height . ";";
        $Format .= "use_preview:" . $format_use_preview . ";";
        $Format .= "preview_width:" . $format_preview_width . ";";
        $Format .= "preview_height:" . $format_preview_height . ";";
    } else {
        if ($TypeOfData_ID == NC_FIELDTYPE_TEXT) {
            $Format = ($format_height ? $format_height : 5) . ":" . ($format_width ? $format_width : 60) . ";";
            $Format .= "html:" . $format_html . ";br:" . $format_br . ";fck:" . $format_fck . ";";
            $Format .= "panel:" . $format_panel . ";typo:" . $format_typo . ";bbcode:" . $format_bbcode . ";";
        } else {
            if ($TypeOfData_ID == NC_FIELDTYPE_DATETIME && $use_calendar) {
                $Format .= ($Format ? ";" : "") . 'calendar';
            } else {
                if ($TypeOfData_ID == NC_FIELDTYPE_STRING) {
                    if ($Format == 'email' && $protect_email) {
                        $Format .= ':protect';
                    } else {
                        $Format .= ':';
                    }
                    if ($use_transliteration) {
                        $Format .= ':' . $use_transliteration;
                        $Format .= ':' . $transliteration_field;
                        $Format .= ':' . $use_url_rules;
                    }
                } else {
                    if ($TypeOfData_ID == NC_FIELDTYPE_MULTIFILE) {
                        $Format .= ";";
                        $Format .= "use_resize:" . $format_use_resize . ";";
                        $Format .= "resize_width:" . $format_resize_width . ";";
                        $Format .= "resize_height:" . $format_resize_height . ";";
                        $Format .= "use_crop:" . $format_use_crop . ";";
                        $Format .= "crop_x0:" . $format_crop_x0 . ";";
                        $Format .= "crop_y0:" . $format_crop_y0 . ";";
                        $Format .= "crop_x1:" . $format_crop_x1 . ";";
                        $Format .= "crop_y1:" . $format_crop_y1 . ";";
                        $Format .= "crop_ignore:" . $format_crop_ignore . ";";
                        $Format .= "crop_ignore_width:" . $format_crop_ignore_width . ";";
                        $Format .= "crop_ignore_height:" . $format_crop_ignore_height . ";";
                        $Format .= "use_preview:" . $format_use_preview . ";";
                        $Format .= "preview_width:" . $format_preview_width . ";";
                        $Format .= "preview_height:" . $format_preview_height . ";";
                    }
                }
            }
        }
    }
    $Description = htmlspecialchars($Description);
    $Extension = $db->escape($Extension);
    // Add new field
    if (!$FieldID) {
        if (count($db->get_results($widgetclass_id ? "SELECT * FROM `Field` WHERE `Widget_Class_ID`='" . $widgetclass_id . "' AND `Field_Name`='" . $FieldName . "'" : "SHOW FIELDS FROM `" . $TableName . "` LIKE '" . $FieldName . "'"))) {
            return -3;
        }
        $fl1 = $isSys ? "`System_Table_ID`" : ($widgetclass_id ? "`Widget_Class_ID`" : "`Class_ID`");
        $fl2 = $isSys ? "`Inheritance`" : "`DoSearch`";
        $insert_field = "`Field` (" . $fl1 . ", " . $fl2 . ", `Field_Name`,`Description`,`TypeOfData_ID`,`Format`,`Extension`, `NotNull`,`Priority`,`DefaultState`,`TypeOfEdit_ID`,`InTableView`)";
        $value = " VALUES ('";
        $value .= $isSys ? $SystemTableID . "','" . $Inheritance : ($widgetclass_id ? $widgetclass_id . "','" . $DoSearch : $ClassID . "','" . $DoSearch);
        $value .= "','" . $FieldName . "','" . $Description . "'," . $TypeOfData_ID . ",'" . $Format . "', '" . $Extension . "' ," . $NotNull . "," . $Priority . ",'" . $DefaultState . "','" . $TypeOfEdit_ID . "','" . $InTableView . "')";
        $query = "INSERT INTO " . $insert_field . $value;
        if (!$FieldName || nc_preg_match("/[^a-zA-Z0-9_]/", $FieldName)) {
            return -1;
        }
        if (!$FieldName || nc_preg_match("/^[\\d]+/", $FieldName)) {
            return -5;
        }
        // check if field name is already exists
        if (!$widgetclass_id) {
            $table = $ClassID ? "`Message" . $ClassID . "`" : $db->get_var("select `System_Table_Name` from `System_Table` where `System_Table_ID`=" . $SystemTableID);
            if ($db->column_exists($table, $FieldName)) {
                return -3;
            }
        }
        if ($db->query($query)) {
            $CurrentFieldID = $db->insert_id;
            if (!$widgetclass_id) {
                ColumnInMessage($CurrentFieldID, 1, $db);
            }
        }
        return $CurrentFieldID;
    } else {
        $NewFieldName = false;
        if (!$widgetclass_id) {
            if (!$FieldName || nc_preg_match("/[^a-zA-Z0-9_]/", $FieldName)) {
                return -1;
            }
            if (!$FieldName || nc_preg_match("/^[\\d]+/", $FieldName)) {
                return -5;
            }
            $sql = "SELECT `Field_Name` FROM `Field` WHERE `Field_ID` = {$FieldID} LIMIT 1";
            $OldFieldName = $db->get_var($sql);
            if ($FieldName != $OldFieldName) {
                if ($db->column_exists($TableName, $FieldName)) {
                    return -3;
                }
                $NewFieldName = $FieldName;
            }
        }
        $query = "UPDATE `Field` SET `Description`='" . $Description . "',`TypeOfData_ID`='" . $TypeOfData_ID . "',`Format`='" . $Format . "', `Extension` = '" . $Extension . "', `NotNull`='" . $NotNull;
        $query .= "',`Priority`='" . $Priority . "',`DefaultState`='" . $DefaultState . "',`TypeOfEdit_ID`='" . $TypeOfEdit_ID . "',`InTableView`='" . $InTableView . "'";
        $query .= $isSys ? ", `Inheritance`='" . $Inheritance . "'" : ", `DoSearch`='" . $DoSearch . "'";
        $query .= " WHERE `Field_ID`='" . $FieldID . "'";
        if (($db->query($query) || $NewFieldName) && !$widgetclass_id) {
            ColumnInMessage($FieldID, 2, $db, $NewFieldName);
        }
        return $FieldID;
    }
    return 0;
}