Пример #1
0
function rex_a62_media_is_in_use($params)
{
    global $REX, $I18N;
    $warning = $params['subject'];
    $sql = rex_sql::factory();
    $sql->setQuery('SELECT `name`, `type` FROM `' . $REX['TABLE_PREFIX'] . '62_params` WHERE `type` IN(6,7)');
    $rows = $sql->getRows();
    if ($rows == 0) {
        return $warning;
    }
    $where = array('articles' => array(), 'media' => array());
    $filename = addslashes($params['filename']);
    for ($i = 0; $i < $rows; $i++) {
        $name = $sql->getValue('name');
        if (a62_meta_prefix($name) == 'med_') {
            $key = 'media';
        } else {
            $key = 'articles';
        }
        switch ($sql->getValue('type')) {
            case '6':
                $where[$key][] = $name . '="' . $filename . '"';
                break;
            case '7':
                $where[$key][] = 'FIND_IN_SET("' . $filename . '", ' . $name . ')';
                break;
            default:
                trigger_error('Unexpected fieldtype "' . $sql->getValue('type') . '"!', E_USER_ERROR);
        }
        $sql->next();
    }
    $articles = '';
    $categories = '';
    if (!empty($where['articles'])) {
        $sql->setQuery('SELECT id, clang, re_id, name, catname, startpage FROM ' . $REX['TABLE_PREFIX'] . 'article WHERE ' . implode(' OR ', $where['articles']));
        if ($sql->getRows() > 0) {
            foreach ($sql->getArray() as $art_arr) {
                $aid = $art_arr['id'];
                $clang = $art_arr['clang'];
                $re_id = $art_arr['re_id'];
                $name = $art_arr['startpage'] ? $art_arr['catname'] : $art_arr['name'];
                if ($art_arr['startpage']) {
                    $categories .= '<li><a href="javascript:openPage(\'index.php?page=structure&amp;edit_id=' . $aid . '&amp;function=edit_cat&amp;category_id=' . $re_id . '&amp;clang=' . $clang . '\')">' . $art_arr['catname'] . '</a></li>';
                } else {
                    $articles .= '<li><a href="javascript:openPage(\'index.php?page=content&amp;article_id=' . $aid . '&amp;mode=meta&amp;clang=' . $clang . '\')">' . $art_arr['name'] . '</a></li>';
                }
            }
            if ($articles != '') {
                $warning[] = $I18N->msg('minfo_media_in_use_art') . '<br /><ul>' . $articles . '</ul>';
            }
            if ($categories != '') {
                $warning[] = $I18N->msg('minfo_media_in_use_cat') . '<br /><ul>' . $categories . '</ul>';
            }
        }
    }
    $media = '';
    if (!empty($where['media'])) {
        $sql->setQuery('SELECT file_id, filename, category_id FROM ' . $REX['TABLE_PREFIX'] . 'file WHERE ' . implode(' OR ', $where['media']));
        if ($sql->getRows() > 0) {
            foreach ($sql->getArray() as $med_arr) {
                $id = $med_arr['file_id'];
                $filename = $med_arr['filename'];
                $cat_id = $med_arr['category_id'];
                $media .= '<li><a href="index.php?page=mediapool&amp;subpage=detail&amp;file_id=' . $id . '&amp;rex_file_category=' . $cat_id . '">' . $filename . '</a></li>';
            }
            if ($media != '') {
                $warning[] = $I18N->msg('minfo_media_in_use_med') . '<br /><ul>' . $media . '</ul>';
            }
        }
    }
    return $warning;
}
function a62_delete_field($fieldIdOrName)
{
    global $REX, $I18N;
    // Löschen anhand der FieldId
    if (is_int($fieldIdOrName)) {
        $fieldQry = 'SELECT * FROM ' . $REX['TABLE_PREFIX'] . '62_params WHERE field_id=' . $fieldIdOrName . ' LIMIT 2';
        $invalidField = $I18N->msg('minfo_field_error_invalid_fieldid');
    } else {
        if (is_string($fieldIdOrName)) {
            $fieldQry = 'SELECT * FROM ' . $REX['TABLE_PREFIX'] . '62_params WHERE name="' . addslashes($fieldIdOrName) . '" LIMIT 2';
            $invalidField = $I18N->msg('minfo_field_error_invalid_name');
        } else {
            trigger_error('MetaInfos: Unexpected type for $fieldIdOrName!', E_USER_ERROR);
        }
    }
    // Feld existiert?
    $sql = rex_sql::factory();
    $fieldInfos = $sql->getArray($fieldQry);
    if ($sql->getRows() != 1) {
        return $invalidField;
    }
    $name = $fieldInfos[0]['name'];
    $field_id = $fieldInfos[0]['field_id'];
    $prefix = a62_meta_prefix($name);
    $metaTable = a62_meta_table($prefix);
    // Spalte existiert?
    $sql->setQuery('SELECT * FROM ' . $metaTable . ' LIMIT 1');
    if (!in_array($name, $sql->getFieldnames())) {
        return $I18N->msg('minfo_field_error_invalid_name');
    }
    $sql->setTable($REX['TABLE_PREFIX'] . '62_params');
    $sql->setWhere('field_id=' . $field_id);
    if (!$sql->delete()) {
        return $sql->getError();
    }
    $tableManager = new rex_a62_tableManager($metaTable);
    return $tableManager->deleteColumn($name);
}