Esempio n. 1
0
/**
 * Almacena los datos del grupo en la base de datos
 **/
function dt_save_group($edit = 0)
{
    global $xoopsSecurity, $functions, $db;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    if (!$xoopsSecurity->check()) {
        $functions->dt_send_message(__('Session token not valid!', 'dtransport'), 1, 0);
    }
    //Verificamos si el software es válido
    if ($item <= 0) {
        $functions->dt_send_message(__('Download item ID has not been specified!', 'dtransport'), 1, 1);
    }
    //Verificamos si existe el software
    $sw = new DTSoftware($item);
    if ($sw->isNew()) {
        $functions->dt_send_message(__('Specified item does not exists!', 'dtransport'), 1, 1);
    }
    if ($edit) {
        //Verificamos si grupo es válido
        if ($id <= 0) {
            $functions->dt_send_message(__('A group ID has not been specified!', 'dtransport'), 1, 1);
        }
        //Verificamos si el grupo existe
        $group = new DTFileGroup($id);
        if ($group->isNew()) {
            $functions->dt_send_message(__('Specified group does not exists!', 'dtransport'), 1, 1);
        }
        //Verificamos si existe el nombre del grupo
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_groups') . " WHERE name='" . $name . "' AND id_soft=" . $item . " AND id_group<>" . $group->id();
        list($num) = $db->fetchRow($db->queryF($sql));
    } else {
        //Verificamos si existe el nombre del grupo
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_groups') . " WHERE name='" . $name . "' AND id_soft=" . $item;
        list($num) = $db->fetchRow($db->queryF($sql));
        $group = new DTFileGroup();
    }
    if ($num > 0) {
        $functions->dt_send_message(__('Another group with same name exists already!', 'dtransport'), 1, 1);
    }
    $group->setName($name);
    $group->setSoftware($item);
    if ($group->save()) {
        $ret = array('message' => __('Database updated successfully!', 'dtransport'), 'name' => $name, 'item' => $item, 'id' => $group->id(), 'action' => $edit ? 'edit' : 'create');
        $functions->dt_send_message($ret, 0, 1);
    } else {
        $functions->dt_send_message(__('Database could not be updated', 'dtransport') . '<br />', $group->errors(), 1, 1);
    }
}
Esempio n. 2
0
/**
* @desc Elimina el grupo especificado
**/
function deleteGroups()
{
    global $xoopsModule, $util, $xoopsSecurity;
    $id = rmc_server_var($_REQUEST, 'id', array());
    $item = rmc_server_var($_REQUEST, 'item', 0);
    if (!$xoopsSecurity->check()) {
        redirectMsg('files.php?item=' . $item, __('Session token not valid!', 'dtransport'), RMMSG_WARN);
        die;
    }
    //Verificamos si el software es válido
    if ($item <= 0) {
        redirectMsg('files.php', __('Download item ID not provided!', 'dtransport'), RMMSG_WARN);
        die;
    }
    //Verificamos si existe el software
    $sw = new DTSoftware($item);
    if ($sw->isNew()) {
        redirectMsg('files.php', __('Specified download item does not exists!', 'dtransport'), RMMSG_WARN);
        die;
    }
    //Verificamos si grupo es válido
    if ($id <= 0) {
        redirectMsg('files.php?item=' . $item, __('Group id not provided!', 'dtransport'), RMMSG_ERROR);
        die;
    }
    //Verificamos si el grupo existe
    $group = new DTFileGroup($id);
    if ($group->isNew()) {
        redirectMsg('files.php?item=' . $item, __('Specified group does not exists!', 'dtransport'), RMMSG_ERROR);
        die;
    }
    if (!$group->delete()) {
        redirectMsg('files.php?item=' . $item, sprintf(__('Group %s could not be deleted!', 'dtransport'), '<strong>' . $group->name() . '</strong>') . '<br />' . $group->errors(), 1);
        die;
    } else {
        redirectMsg('files.php?item=' . $item, sprintf(__('Group %s deleted successfully!', 'dtransport'), '<strong>' . $group->name() . '</strong>'), 0);
        die;
    }
}