Beispiel #1
0
/**
 * @hook example_add_row_action(array(<ExampleData> 'data', <String> 'actions')
 * @param Web $w
 */
function index_ALL(Web $w)
{
    // adding data to the template context
    $w->ctx("message", "Example Data List");
    // get the list of data objects
    $listdata = $w->Example->getAllData();
    // prepare table data
    $t[] = array("Title", "Data", "Actions");
    // table header
    if (!empty($listdata)) {
        foreach ($listdata as $d) {
            $row = array();
            $row[] = $d->title;
            $row[] = $d->data;
            // prepare action buttons for each row
            $actions = array();
            if ($d->canEdit($w->Auth->user())) {
                $actions[] = Html::box("/example/edit/" . $d->id, "Edit", true);
            }
            if ($d->canDelete($w->Auth->user())) {
                $actions[] = Html::b("/example/delete/" . $d->id, "Delete", "Really delete?");
            }
            // allow any other module to add actions here
            $actions = $w->callHook("example", "add_row_action", array("data" => $d, "actions" => $actions));
            $row[] = implode(" ", $actions);
            $t[] = $row;
        }
    }
    // create the html table and put into template context
    $w->ctx("table", Html::table($t, "table", "tablesorter", true));
}
Beispiel #2
0
/**
 * Handle User Edit form submission
 *
 * @param <type> $w
 */
function useredit_POST(Web &$w)
{
    $w->pathMatch("id");
    $errors = $w->validate(array(array("login", ".+", "Login is mandatory")));
    if ($_REQUEST['password'] && $_REQUEST['password'] != $_REQUEST['password2']) {
        $error[] = "Passwords don't match";
    }
    $user = $w->Auth->getObject("User", $w->ctx('id'));
    if (!$user) {
        $errors[] = "User does not exist";
    }
    if (sizeof($errors) != 0) {
        $w->error(implode("<br/>\n", $errors), "/admin/useredit/" . $w->ctx("id"));
    }
    $user->login = $_REQUEST['login'];
    $user->fill($_REQUEST);
    if ($_REQUEST['password']) {
        $user->setPassword($_REQUEST['password']);
    } else {
        $user->password = null;
    }
    $user->is_admin = isset($_REQUEST['is_admin']) ? 1 : 0;
    $user->is_active = isset($_REQUEST['is_active']) ? 1 : 0;
    $user->update();
    $contact = $user->getContact();
    if ($contact) {
        $contact->fill($_REQUEST);
        $contact->private_to_user_id = null;
        $contact->update();
    }
    $w->callHook("admin", "account_changed", $user);
    $w->msg("User " . $user->login . " updated.", "/admin/users");
}
Beispiel #3
0
/**
 * Handle User Edit form submission
 *
 * @param <type> $w
 */
function useradd_POST(Web &$w)
{
    $errors = $w->validate(array(array("login", ".+", "Login is mandatory"), array("password", ".+", "Password is mandatory"), array("password2", ".+", "Password2 is mandatory")));
    if ($_REQUEST['password2'] != $_REQUEST['password']) {
        $errors[] = "Passwords don't match";
    }
    if (sizeof($errors) != 0) {
        $w->error(implode("<br/>\n", $errors), "/admin/useradd");
    }
    // first saving basic contact info
    $contact = new Contact($w);
    $contact->fill($_REQUEST);
    $contact->dt_created = time();
    $contact->private_to_user_id = null;
    $contact->insert();
    // now saving the user
    $user = new User($w);
    $user->login = $_REQUEST['login'];
    $user->setPassword($_REQUEST['password']);
    $user->is_active = !empty($_REQUEST['is_active']) ? $_REQUEST['is_active'] : 0;
    $user->is_admin = !empty($_REQUEST['is_admin']) ? $_REQUEST['is_admin'] : 0;
    $user->is_group = 0;
    $user->dt_created = time();
    $user->contact_id = $contact->id;
    $user->insert();
    $w->ctx("user", $user);
    // now saving the roles
    $roles = $w->Auth->getAllRoles();
    foreach ($roles as $r) {
        if (!empty($_REQUEST["check_" . $r])) {
            if ($_REQUEST["check_" . $r] == 1) {
                $user->addRole($r);
            }
        }
    }
    $w->callHook("admin", "account_changed", $user);
    $w->msg("User " . $user->login . " added", "/admin/users");
}