示例#1
0
/**
* Save feature
*/
function dt_save_feature($edit)
{
    global $item, $feature, $tpl, $xoopsTpl, $mc, $dtfunc;
    $query = '';
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    if ($edit) {
        //Verificamos que la característica exista
        $ft = new DTFeature($feature);
        if ($ft->isNew()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/features/' . $item->id() . '/' : '/?p=cpanel&action=features&id=' . $item->id()), 1, __('Specified feature does not exists!', 'dtransport'));
        }
    } else {
        $ft = new DTFeature();
    }
    $tc = TextCleaner::getInstance();
    if (trim($nameid) == '') {
        $nameid = $tc->sweetstring($title);
    } else {
        $nameid = $tc->sweetstring($nameid);
    }
    //Comprueba que el título de la característica no exista
    $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_features') . " WHERE (title='{$title}' OR nameid='{$nameid}' AND id_feat!=" . $ft->id() . " AND id_soft=" . $item->id();
    list($num) = $db->fetchRow($db->queryF($sql));
    if ($num > 0) {
        redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/features/' . $item->id() . '/edit/' . $ft->id() : '/?p=cpanel&action=features&id=' . $item->id() . '/&op=edit&feature=' . $ft->id()), 1, __('Another feature with same title already exists!', 'dtransport'));
    }
    $ft->setSoftware($item->id());
    $ft->setTitle($title);
    $ft->setContent($content);
    if (!$edit) {
        $ft->setCreated(time());
    }
    $ft->setModified(time());
    $ft->setNameId($nameid);
    if (!$ft->save()) {
        redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/features/' . $item->id() . '/' : '/?p=cpanel&action=features&id=' . $item->id()), 1, __('Feature could not be saved! Please try again.', 'dtransport'));
    }
    if (!$dtfunc->save_meta('feat', $ft->id())) {
        redirectMsg(DT_URL . ($mc['permalinks'] ? '/cp/features/' . $item->id() . '/' : '/?p=cpanel&action=features&id=' . $item->id()), 1, __('Feature saved correctly, however custom fields could not be stored in database!', 'dtransport'));
    }
    redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/features/' . $item->id() . '/' : '/?p=cpanel&action=features&id=' . $item->id()), 1, __('Featured saved successfully!', 'dtransport'));
}
示例#2
0
/**
* @desc Almacena la característica en la base de datos
**/
function dt_save_features($edit = 0)
{
    global $xoopsSecurity, $functions;
    $query = '';
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
        if ($k == 'XOOPS_TOKEN_REQUEST' || $k == 'action') {
            continue;
        }
        $query = $query == '' ? $k . '=' . urlencode($v) : '&' . $k . '=' . urlencode($v);
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('features.php?action=' . ($edit ? 'edit&id=' . $id : 'new') . '&item=' . $item, __('Session token not valid!', 'dtransport'), RMMSG_ERROR);
    }
    //Verificamos que el software sea válido
    if ($item <= 0) {
        redirectMsg('items.php', __('Download item ID not provided!', 'dtransport'), RMMSG_WARN);
    }
    //Verificamos que el software exista
    $sw = new DTSoftware($item);
    if ($sw->isNew()) {
        redirectMsg('items.php', __('Specified download item does not exists!', 'dtransport'), RMMSG_ERROR);
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    if ($edit) {
        if ($id <= 0) {
            redirectMsg('features.php?item=' . $item, __('Feature ID not specified!', 'dtransport'), RMMSG_WARN);
        }
        //Verificamos que la característica exista
        $ft = new DTFeature($id);
        if ($ft->isNew()) {
            redirectMsg('features.php?item=' . $item, __('Specified feature does not exists!', 'dtransport'), RMMSG_ERROR);
        }
    } else {
        $ft = new DTFeature();
    }
    $tc = TextCleaner::getInstance();
    if (trim($nameid) == '') {
        $nameid = $tc->sweetstring($title);
    } else {
        $nameid = $tc->sweetstring($nameid);
    }
    //Comprueba que el título de la característica no exista
    $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_features') . " WHERE (title='{$title}' OR nameid='{$nameid}' AND id_feat<>" . $ft->id() . " AND id_soft=" . $item;
    list($num) = $db->fetchRow($db->queryF($sql));
    if ($num > 0) {
        redirectMsg('features.php?' . $query . ($edit ? '&action=edit' : '&action=new'), __('Another feature with same title already exists!', 'dtransport'), RMMSG_WARN);
    }
    $ft->setSoftware($item);
    $ft->setTitle($title);
    $ft->setContent($content);
    if (!$edit) {
        $ft->setCreated(time());
    }
    $ft->setModified(time());
    $ft->setNameId($nameid);
    if (!$ft->save()) {
        redirectMsg('features.php?' . $query . ($edit ? '&action=edit' : '&action=new'), __('Feature could not be saved!', 'dtransport') . '<br />' . $ft->errors(), 1);
    }
    if (!$functions->save_meta('feat', $ft->id())) {
        redirectMsg('features.php?item=' . $item, __('Feature saved correctly, however custom fields could not be stored in database!', 'dtransport'), RMMSG_INFO);
    }
    redirectMsg('features.php?item=' . $item, __('Featured saved successfully!', 'dtransport'), RMMSG_SAVED);
}