Example #1
0
/**
* @desc Visualiza todos los clientes
**/
function showClients()
{
    global $xoopsModule, $xoopsSecurity;
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    //Barra de Navegación
    $sql = "SELECT COUNT(*) FROM " . $db->prefix('pw_clients');
    list($num) = $db->fetchRow($db->query($sql));
    $page = rmc_server_var($_GET, 'page', 1);
    $limit = 15;
    $tpages = ceil($num / $limit);
    $page = $page > $tpages ? $tpages : $page;
    $start = $num <= 0 ? 0 : ($page - 1) * $limit;
    $nav = new RMPageNav($num, $limit, $page, 5);
    $nav->target_url('clients.php?page={PAGE_NUM}');
    $sql = "SELECT * FROM " . $db->prefix('pw_clients') . " ORDER BY id_client";
    $sql .= " LIMIT {$start},{$limit}";
    $result = $db->query($sql);
    $customers = array();
    while ($rows = $db->fetchArray($result)) {
        $client = new PWClient();
        $client->assignVars($rows);
        $type = new PWType($client->type());
        $customers[] = array('id' => $client->id(), 'name' => $client->name(), 'business' => $client->businessName(), 'type' => $type->type(), 'description' => $client->desc());
    }
    // Event
    $customers = RMEvents::get()->run_event('works.list.customers', $customers);
    PWFunctions::toolbar();
    RMTemplate::get()->add_style('admin.css', 'works');
    xoops_cp_location('<a href="./">' . $xoopsModule->name() . "</a> &raquo; " . __('Customers', 'works'));
    RMTemplate::get()->assign('xoops_pagetitle', __('Customers', 'works'));
    RMTemplate::get()->add_script('../include/js/admin_works.js');
    RMTemplate::get()->add_head("<script type='text/javascript'>\nvar pw_message='" . __('Do you really want to delete selected customers?', 'works') . "';\n\n        var pw_select_message = '" . __('You must select some customer before to execute this action!', 'works') . "';</script>");
    xoops_cp_header();
    include RMTemplate::get()->get_template('admin/pw_clients.php', 'module', 'works');
    xoops_cp_footer();
}
Example #2
0
/**
* @desc Elimina los tipos de cliente porporcionados
**/
function deleteTypes()
{
    global $xoopsSecurity;
    $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
    $ok = isset($_POST['ok']) ? intval($_POST['ok']) : 0;
    //Verificamos que nos hayan proporcionado un tipo para eliminar
    if (!is_array($ids)) {
        redirectMsg('./types.php', __('You has not selected any customer type to delete!', 'works'), 1);
        die;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('./types.php', __('Session token expired!', 'works'), 1);
        die;
    }
    $errors = '';
    foreach ($ids as $k) {
        //Verificamos si el tipo sea válido
        if ($k <= 0) {
            $errors .= sprintf(__('Customer type id "%u" is not valid!', 'works'), $k);
            continue;
        }
        //Verificamos siel tipo existe
        $type = new PWType($k);
        if ($type->isNew()) {
            $errors .= sprintf(__('Customer type with id "%u" does not exists!', 'works'), $k);
            continue;
        }
        if (!$type->delete()) {
            $errors .= sprintf(__('Type %s could not be deleted!', 'works'), $type->type());
        }
    }
    if ($errors != '') {
        redirectMsg('./types.php', __('Errors ocurred while trying to delete selected types') . '<br />' . $errors, 1);
        die;
    } else {
        redirectMsg('./types.php', __('Customer types deleted successfully!', 'works'), 0);
        die;
    }
}