Esempio n. 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));
}
Esempio n. 2
0
function admin_ALL(Web $w)
{
    History::add("Workhours Admin");
    $w->ctx("workperiods", $w->Bend->getAllWorkPeriods());
    $w->ctx("focusgroups", $w->Bend->getTopLevelWorkCategories());
    $w->enqueueStyle(["uri" => "/modules/bend/assets/css/bend.css", "weight" => 500]);
}
Esempio n. 3
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");
}
Esempio n. 4
0
function listwidgets_ALL(Web $w, $params)
{
    $module = null;
    if (!empty($params["module"])) {
        $module = $params["module"];
    } else {
        $module = $w->_module;
    }
    $widgets = $w->Widget->getWidgetsForModule($module, $w->Auth->user()->id);
    $filter_widgets = array();
    if (!empty($widgets)) {
        // Filter out widgets in an inactive class
        $filter_widgets = array_filter($widgets, function ($widget) use($w) {
            return $w->isClassActive($widget->widget_name);
        });
        foreach ($filter_widgets as &$widget) {
            // Give each widget_config db object an instance of the matching class
            $widget_class = null;
            $widgetname = $widget->widget_name;
            $widget->widget_class = new $widgetname($w, $widget);
        }
    }
    $w->ctx("columns", 3);
    $w->ctx("widgets", $filter_widgets);
    $w->ctx("module", $module);
}
Esempio n. 5
0
function listtaskgroups_ALL(Web $w, $params = array())
{
    $taskgroups = $params['taskgroups'];
    $should_filter = !empty($params['should_filter']) ? $params['should_filter'] : false;
    $filter_closed_tasks = !empty($params['filter_closed_tasks']) ? $params['filter_closed_tasks'] : false;
    if ($should_filter) {
        $taskgroups = array_filter($taskgroups, function ($taskgroup) use($w, $filter_closed_tasks) {
            // First check if there are tasks
            $tasks = $taskgroup->getTasks();
            if (count($tasks) == 0) {
                return false;
            } else {
                // Check if any of the tasks are accessible to the user
                $tasks = array_filter($tasks, function ($task) use($w, $filter_closed_tasks) {
                    if ($filter_closed_tasks && $task->isStatusClosed()) {
                        return false;
                    } else {
                        return $task->getCanIView();
                    }
                });
                // If there are tasks that the user can view then show the taskgroup
                return count($tasks) > 0;
            }
        });
    }
    $w->ctx("taskgroups", $taskgroups);
    $w->ctx("redirect", $params['redirect']);
}
Esempio n. 6
0
function listcomments_ALL(Web $w, $params)
{
    $object = $params['object'];
    $redirect = $params['redirect'];
    $w->ctx("comments", $w->Comment->getCommentsForTable($object->getDbTableName(), $object->id));
    $w->ctx("redirect", $redirect);
    $w->ctx("object", $object);
}
Esempio n. 7
0
function displaycomment_ALL(Web $w, $params)
{
    if (!empty($params['redirect'])) {
        $w->ctx("redirect", $params['redirect']);
    }
    if (!empty($params['displayOnly'])) {
        $w->ctx("displayOnly", true);
    }
    $w->ctx("c", $params['object']);
}
Esempio n. 8
0
function showtaskgroup_ALL(Web $w, $params)
{
    $taskgroup = $params["taskgroup"];
    if (!empty($taskgroup)) {
        $taskgroup->tasks = $w->Task->getTasksbyGroupId($taskgroup->id);
        $taskgroup->statuses = $w->Task->getTaskTypeStatus($taskgroup->task_group_type);
        $w->ctx("taskgroup", $taskgroup);
    }
    $w->ctx("redirect", !empty($params["redirect"]) ? $params["redirect"] : "/");
}
Esempio n. 9
0
function showperiod_GET(Web $w)
{
    list($id) = $w->pathMatch("a");
    $wp = $w->Bend->getWorkperiodForId($id);
    if (empty($wp)) {
        $w->error("Workperiod does not exist", "/bend-workhours/admin");
    }
    History::add("Work Period: " . formatDate($wp->d_start));
    $w->ctx("workperiod", $wp);
    $w->ctx("categories", $w->Bend->getTopLevelWorkCategories());
    $w->ctx("households", $w->Bend->getAllHouseholds());
}
Esempio n. 10
0
/**
 * This function is called AFTER the action was executed
 * 
 * @param unknown $w
 */
function example_listener_POST_ACTION(Web $w)
{
    // you can find out which objects have changed
    $updated = $w->ctx("db_updated");
    // returns array("classname" => array($id1, $id2, ..), ..);
    $deleted = $w->ctx("db_deleted");
    // returns array("classname" => array($id1, $id2, ..), ..);
    $inserts = $w->ctx("db_inserts");
    // returns array("classname" => array($id1, $id2, ..), ..);
    // you can redirect the request.. but maybe you shouldn't!
    $w->redirect("/main");
}
Esempio n. 11
0
function printers_GET(Web $w)
{
    $printers = $w->Printer->getPrinters();
    $table_data = array();
    $table_header = array("Name", "Server", "Port", "Actions");
    if (!empty($printers)) {
        foreach ($printers as $printer) {
            $table_data[] = array($printer->name, $printer->server, $printer->port, Html::box("/admin/editprinter/{$printer->id}", "Edit", true) . Html::b("/admin/deleteprinter/{$printer->id}", "Delete", "Are you sure you want to delete this printer?"));
        }
    }
    $w->ctx("table_header", $table_header);
    $w->ctx("table_data", $table_data);
}
Esempio n. 12
0
 /**
  * Channels naivgation function
  * @return none
  */
 public function navigation(Web $w, $title = null, $prenav = null)
 {
     if ($title) {
         $w->ctx("title", $title);
     }
     $nav = $prenav ? $prenav : array();
     if ($w->Auth->loggedIn()) {
         $w->menuLink("channels/listchannels", "List Channels", $nav);
         $w->menuLink("channels/listprocessors", "List Processors", $nav);
         $w->menuLink("channels/listmessages", "List Messages", $nav);
     }
     $w->ctx("navigation", $nav);
     return $nav;
 }
Esempio n. 13
0
/**
 * Partial action that lists favorite objects
 * @author Steve Ryan steve@2pisoftware.com 2015
 */
function listfavorite_ALL(Web $w, $params)
{
    $user = $w->Auth->user();
    if (!empty($user)) {
        $results = $w->Favorite->getDataByUser($user->id);
        $favoritesCategorised = array();
        $service = new DBService($w);
        if (!empty($results)) {
            foreach ($results as $k => $favorite) {
                if (!array_key_exists($favorite->object_class, $favoritesCategorised)) {
                    $favoritesCategorised[$favorite->object_class] = array();
                }
                $realObject = $service->getObject($favorite->object_class, $favorite->object_id);
                if (!empty($realObject)) {
                    $templateData = array();
                    $templateData['title'] = $realObject->printSearchTitle();
                    $templateData['url'] = $realObject->printSearchUrl();
                    $templateData['listing'] = $realObject->printSearchListing();
                    if ($realObject->canList($user) && $realObject->canView($user)) {
                        array_push($favoritesCategorised[$favorite->object_class], $templateData);
                    }
                }
            }
        }
        $w->ctx('categorisedFavorites', $favoritesCategorised);
    }
}
Esempio n. 14
0
function profile_GET(Web &$w)
{
    $p = $w->pathMatch("box");
    $user = $w->Auth->user();
    $contact = $user->getContact();
    if ($user) {
        $w->ctx("title", "Administration - Profile - " . $user->login);
    } else {
        $w->error("User does not exist.");
    }
    $lines = array();
    $lines[] = array("Change Password", "section");
    $lines[] = array("Password", "password", "password", "");
    $lines[] = array("Repeat Password", "password", "password2", "");
    $lines[] = array("Contact Details", "section");
    $lines[] = array("First Name", "text", "firstname", $contact ? $contact->firstname : "");
    $lines[] = array("Last Name", "text", "lastname", $contact ? $contact->lastname : "");
    $lines[] = array("Communication", "section");
    $lines[] = array("Home Phone", "text", "homephone", $contact ? $contact->homephone : "");
    $lines[] = array("Work Phone", "text", "workphone", $contact ? $contact->workphone : "");
    $lines[] = array("Private Mobile", "text", "priv_mobile", $contact ? $contact->priv_mobile : "");
    $lines[] = array("Work Mobile", "text", "mobile", $contact ? $contact->mobile : "");
    $lines[] = array("Fax", "text", "fax", $contact ? $contact->fax : "");
    $lines[] = array("Email", "text", "email", $contact ? $contact->email : "");
    $lines[] = array("Redirect URL", "text", "redirect_url", $user->redirect_url);
    $f = Html::form($lines, $w->localUrl("/auth/profile"), "POST", "Update");
    if ($p['box']) {
        $w->setLayout(null);
        $f = "<h2>Edit Profile</h2>" . $f;
    }
    $w->out($f);
}
Esempio n. 15
0
function atdel_GET(Web &$w)
{
    $p = $w->pathMatch("id", "url");
    $att = $w->service("File")->getAttachment($p['id']);
    if ($att) {
        $w->ctx('attach_id', $att->id);
        $w->ctx('attach_table', $att->parent_table);
        $w->ctx('attach_table_id', $att->parent_id);
        $w->ctx('attach_title', $att->title);
        $w->ctx('attach_description', $att->description);
        $att->delete();
        $w->msg("Attachment deleted.", "/" . str_replace(" ", "/", $p['url']));
    } else {
        $w->error("Attachment does not exist.", "/" . str_replace(" ", "/", $p['url']));
    }
}
Esempio n. 16
0
function view_GET(Web &$w)
{
    $p = $w->pathMatch("m", "a");
    // first see if we need to split into sub modules
    $module = $p['m'];
    $action = $p['a'];
    // check if help is allowed for this topic
    if (!$w->Auth->allowed($p['m'] . '/' . $p['a'])) {
        $w->ctx("help_content", "Sorry, there is no help for this topic.");
    }
    $submodule = "";
    // check for submodule
    if (strcontains($p['m'], array("-"))) {
        $ms = explode("-", $p['m']);
        $module = $ms[0];
        $submodule = $ms[1];
    }
    // find a module toc
    $tocf = getHelpFileContent($w, $module, null, $module . "_toc");
    if ($tocf) {
        $w->ctx("module_toc", $module . '/' . $module . "_toc");
        $w->ctx("module_title", HelpLib::extractTitle($tocf));
    }
    // load help file
    $help_file = HelpLib::getHelpFilePath($w, $module, $submodule, $action);
    $content = "Sorry, this help topic is not yet written.";
    if (file_exists($help_file)) {
        $content = file_get_contents($help_file);
    }
    // set context
    $w->ctx("help_content", helpMarkup(pruneRestricted($w, $content), $module));
    $w->ctx("module", $module);
    $w->ctx("submodule", $submodule);
    $w->ctx("action", $action);
}
Esempio n. 17
0
function printview_GET(Web &$w)
{
    $p = $w->pathMatch("table", "id");
    $attachments = $w->service("File")->getAttachments($p['table'], $p['$id']);
    $w->ctx("attachments", $attachments);
    $w->setLayout(null);
}
Esempio n. 18
0
function index_ALL(Web &$w)
{
    // $w->out(print_r($w->Search->getIndexes(),true));
    $w->ctx("indexes", $w->Search->getIndexes());
    if ($w->request("isbox") !== NULL) {
        $w->setLayout(null);
    }
}
Esempio n. 19
0
function showlot_GET(Web $w)
{
    list($id) = $w->pathMatch("id");
    if (empty($id)) {
        $w->error("Need a Lot ID");
    }
    $lot = $w->Bend->getLotForId($id);
    if (empty($lot)) {
        $w->error("Lot {$id} does not exist");
    }
    History::add("Bend Lot: " . $lot->lot_number);
    $lotTable = array();
    $lotTable["Lot"] = array(array(array("Lot Number", "static", "", $lot->lot_number), array("Occupancy", "static", "", $lot->occupancy)));
    $w->ctx("lot", $lot);
    $w->ctx("lotTable", Html::multiColTable($lotTable));
    $w->ctx("owners", $lot->getAllOwners());
    $w->ctx("households", $lot->getAllHouseholds());
}
Esempio n. 20
0
function report_core_web_before_get(Web $w)
{
    // build Navigation to Reports for current Module
    if ($w->Auth->loggedIn()) {
        $reports = $w->Report->getReportsforNav();
        if ($reports) {
            $w->ctx("reports", $reports);
        }
    }
}
Esempio n. 21
0
function login_GET(Web $w)
{
    // Check if logged in already
    $user = $w->Auth->user();
    if ($w->Auth->loggedIn() && $w->Auth->allowed($user->redirect_url)) {
        $w->redirect($w->localUrl(!empty($user->redirect_url) ? $user->redirect_url : "/main"));
    }
    $loginform = Html::form(array(array("Application Login", "section"), array("Username", "text", "login"), array("Password", "password", "password")), $w->localUrl("auth/login"), "POST", "Login");
    $w->ctx("loginform", $loginform);
}
Esempio n. 22
0
function editmember_GET(Web &$w)
{
    $p = $w->pathMatch("repid", "userid");
    // get member details for edit
    $member = $w->Report->getReportMember($p['repid'], $p['userid']);
    // build editable form for a member allowing change of membership type
    $f = Html::form(array(array("Member Details", "section"), array("", "hidden", "report_id", $p['repid']), array("Name", "static", "name", $w->Report->getUserById($member->user_id)), array("Role", "select", "role", $member->role, $w->Report->getReportPermissions())), $w->localUrl("/report/editmember/" . $p['userid']), "POST", " Update ");
    // display form
    $w->setLayout(null);
    $w->ctx("editmember", $f);
}
Esempio n. 23
0
 public function navigation(Web $w, $title = null, $prenav = null)
 {
     if ($title) {
         $w->ctx("title", $title);
     }
     $nav = $prenav ? $prenav : array();
     if ($w->Auth->loggedIn()) {
         $w->menuLink("admin/users", "List Users", $nav);
         $w->menuLink("admin/groups", "List Groups", $nav);
         $w->menuLink("admin/lookup", "Lookup", $nav);
         $w->menuLink("admin-templates", "Templates", $nav);
         $w->menuLink("admin/phpinfo", "PHP Info", $nav);
         $w->menuLink("admin/printers", "Printers", $nav);
         $w->menuLink("admin/printqueue", "Print Queue", $nav);
         $w->menuLink("admin/databasebackup", "Backup Database", $nav);
         $w->menuLink("admin/composer", "Install/Update Composer", $nav, null, "_blank");
     }
     $w->ctx("navigation", $nav);
     return $nav;
 }
Esempio n. 24
0
function addwidget_GET(Web $w)
{
    $p = $w->pathMatch("module");
    $module = $p["module"];
    $modulelist = $w->modules();
    $modules = array_filter($modulelist, function ($module) use(&$w) {
        $names = $w->Widget->getWidgetNamesForModule($module);
        return !empty($names);
    });
    $form = array("Add a widget" => array(array(array("Source module", "select", "source_module", null, $modules)), array(array("Widget Name", "select", "widget_name", null, array()))));
    $w->ctx("widgetform", Html::multiColForm($form, "/main/addwidget/{$module}", "POST", "Add"));
}
Esempio n. 25
0
 static function viewMemberstab(Web &$w, $id)
 {
     // return list of members of given report
     $members = $w->Report->getReportMembers($id);
     // get report details
     $report = $w->Report->getReportInfo($id);
     // set columns headings for display of members
     $line[] = array("Member", "Role", "");
     // if there are members, display their full name, role and button to delete the member
     if ($members) {
         foreach ($members as $member) {
             $line[] = array($w->Report->getUserById($member->user_id), $member->role, Html::box("/report/editmember/" . $report->id . "/" . $member->user_id, " Edit ", true) . "&nbsp;&nbsp;" . Html::box("/report/deletemember/" . $report->id . "/" . $member->user_id, " Delete ", true));
         }
     } else {
         // if there are no members, say as much
         $line[] = array("Group currently has no members. Please Add New Members.", "", "");
     }
     $w->ctx("reportid", $report->id);
     // display list of group members
     $w->ctx("viewmembers", Html::table($line, null, "tablesorter", true));
 }
Esempio n. 26
0
function list_GET(Web $w)
{
    History::add("List Workhours");
    list($userid, $periodid) = $w->pathMatch("a", "b");
    // get the user
    if (!empty($userid)) {
        $user = $w->Auth->getUser($userid);
    } else {
        $user = $w->Auth->user();
    }
    // calculate total work hours for this period
    $workentries = $w->Bend->getWorkhoursForUser($user, $periodid);
    $total_worked = 0;
    $total_accredited = 0;
    if (!empty($workentries)) {
        foreach ($workentries as $we) {
            $total_worked += $we->hours;
            if ($we->user_id == $we->attributed_user_id) {
                $total_accredited += $we->hours;
            }
        }
    }
    $w->ctx("total_worked", $total_worked);
    $w->ctx("total_accredited", $total_accredited);
    $w->ctx("user", $user);
    $w->ctx("workentries", $workentries);
    $w->ctx("workPeriod", $w->Bend->getWorkPeriodForId($periodid));
    $w->ctx("allWorkPeriods", $w->Bend->getAllWorkPeriods());
}
Esempio n. 27
0
function attach_POST(Web &$w)
{
    $table = $w->request('table');
    $id = $w->request('id');
    $title = $w->request('title');
    $description = $w->request('description');
    $type_code = $w->request('type_code');
    $url = str_replace(" ", "/", $w->request('url'));
    $object = $w->Auth->getObject($table, $id);
    if (!$object) {
        $w->error("Nothing to attach to.", $url);
    }
    $aid = $w->service("File")->uploadAttachment("file", $object, $title, $description, $type_code);
    if ($aid) {
        $w->ctx('attach_id', $aid);
        $w->ctx('attach_table', $table);
        $w->ctx('attach_table_id', $id);
        $w->ctx('attach_title', $title);
        $w->ctx('attach_description', $description);
        $w->ctx('attach_type_code', $type_code);
        $w->msg("File attached.", $url);
    } else {
        $w->error("There was an error. Attachment could not be saved.", $url);
    }
}
Esempio n. 28
0
function index_ALL(Web $w)
{
    $connections = $w->Report->getConnections();
    $table_header = array("Driver", "Host", "Database", "Port", "Username", "Actions");
    $table_body = array();
    if (!empty($connections)) {
        foreach ($connections as $conn) {
            $conn->decrypt();
            $table_body[] = array($conn->db_driver, $conn->db_host, $conn->db_database, $conn->db_port, $conn->s_db_user, Html::box("/report-connections/test/{$conn->id}", "Test Connection", true) . Html::box("/report-connections/edit/{$conn->id}", "Edit", true) . Html::b("/report-connections/delete/{$conn->id}", "Delete", "Are you sure you want to remove this connection?"));
        }
    }
    $w->ctx("connections_table", Html::table($table_body, null, "tablesorter", $table_header));
}
Esempio n. 29
0
function forgotpassword_GET(Web $w)
{
    // Check if logged in already
    $user = $w->Auth->user();
    if ($w->Auth->loggedIn() && $w->Auth->allowed($user->redirect_url)) {
        $w->redirect($w->localUrl(!empty($user->redirect_url) ? $user->redirect_url : "/main"));
    }
    // $loginform = Html::form(array(
    // array("Reset Password","section"),
    // array("Your Login","text","login"),
    // ),$w->localUrl("auth/forgotpassword"),"POST","Reset");
    // $w->out($loginform);
    $w->ctx("pagetitle", "Forgot Password");
}
Esempio n. 30
0
function deletemember_GET(Web &$w)
{
    $p = $w->pathMatch("report_id", "user_id");
    // get details of member to be deleted
    $member = $w->Report->getReportMember($p['report_id'], $p['user_id']);
    if ($member) {
        // build a static form displaying members details for confirmation of delete
        $f = Html::form(array(array("Confirm Delete Member", "section"), array("", "hidden", "is_deleted", "1"), array("Name", "static", "name", $w->Report->getUserById($member->user_id))), $w->localUrl("/report/deletemember/" . $member->report_id . "/" . $member->user_id), "POST", " Delete ");
    } else {
        $f = "No such member?";
    }
    // display form
    $w->setLayout(null);
    $w->ctx("deletemember", $f);
}