Inheritance: extends Base
Example #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));
}
Example #2
0
/**
 * updates or removes favorited item 
 *
 * @author Steve Ryan, steve@2pisystems.com, 2015
 **/
function ajaxEditFavorites_ALL(Web $w)
{
    $id = $w->request("id");
    $class = $w->request("class");
    $user = $w->Auth->user();
    $cmd = $w->request("cmd");
    if (!empty($id) && !empty($class) && !empty($user) && !empty($cmd)) {
        if ($cmd == "add") {
            $favorite = new Favorite($w);
            $favorite->object_class = $class;
            $favorite->object_id = $id;
            $favorite->user_id = $user->id;
            $favorite->insertOrUpdate();
            echo $w->Favorite->getFavoriteButton($id, $class);
        } else {
            if ($cmd == "remove") {
                $favorite = $w->Favorite->getDataByObject($id, $class);
                if (get_class($favorite) == "Favorite" && $favorite->id > 0) {
                    $favorite->delete();
                }
                echo $w->Favorite->getFavoriteButton($id, $class);
            } else {
                echo "Invalid request";
            }
        }
    } else {
        echo "Invalid request";
    }
}
Example #3
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']);
}
Example #4
0
function delete_ALL(Web $w)
{
    $p = $w->pathMatch("id");
    if (empty($p['id'])) {
        $w->error("Group not found", "/admin-groups");
    }
    $group = $w->Auth->getUser($p['id']);
    if (empty($group->id)) {
        $w->error("Group not found", "/admin-groups");
    }
    $group->delete();
    $roles = $group->getRoles();
    if (!empty($roles)) {
        foreach ($roles as $role) {
            $group->removeRole($role);
        }
    }
    $members = $w->Auth->getGroupMembers($option['group_id']);
    if ($members) {
        foreach ($members as $member) {
            $member->delete();
        }
    }
    $w->msg("Group deleted", "/admin-groups");
}
function taskAjaxTypetoPriority_ALL(Web &$w)
{
    $priority = array();
    // split the query string into type, group and assignee
    list($type, $group, $assignee) = preg_split('/_/', $w->request('id'));
    // organise criteria
    $who = $assignee != "" ? $assignee : null;
    $where = "";
    if ($group != "") {
        $where .= "task_group_id = " . $group . " and ";
    }
    if ($type != "") {
        $where .= "task_type = '" . $type . "' and ";
    }
    $where .= "is_closed = 0";
    // get priorities from available task list
    $tasks = $w->Task->getTasks($who, $where);
    if ($tasks) {
        foreach ($tasks as $task) {
            if (!array_key_exists($task->priority, $priority)) {
                $priority[$task->priority] = array($task->priority, $task->priority);
            }
        }
    }
    if (!$priority) {
        $priority = array(array("No assigned Tasks", ""));
    }
    // load priority dropdown and return
    $priority = Html::select("tpriority", $priority, null);
    $w->setLayout(null);
    $w->out(json_encode($priority));
}
Example #6
0
function get_GET(Web &$w)
{
    $w->setLayout(null);
    $p = $w->pathMatch("classname", "id");
    $token = $w->request("token");
    $w->out($w->Rest->getJson($p['classname'], $p['id'], $token));
}
Example #7
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);
}
function taskAjaxPrioritytoStatus_ALL(Web &$w)
{
    $status = array();
    // split query string into proirity, type, group and assignee
    list($priority, $type, $group, $assignee) = preg_split('/_/', $w->request('id'));
    // organise criteria
    $who = $assignee != "" ? $assignee : null;
    $where = "";
    if ($group != "") {
        $where .= "task_group_id = " . $group . " and ";
    }
    if ($type != "") {
        $where .= "task_type = '" . $type . "' and ";
    }
    if ($priority != "") {
        $where .= "priority = '" . $priority . "' and ";
    }
    $where .= "is_closed = 0";
    // get statuses from available tasks
    $tasks = $w->Task->getTasks($who, $where);
    if ($tasks) {
        foreach ($tasks as $task) {
            if (!array_key_exists($task->status, $status)) {
                $status[$task->status] = array($task->status, $task->status);
            }
        }
    }
    if (!$status) {
        $status = array(array("No assigned Tasks", ""));
    }
    // load status dropdown and return
    $status = Html::select("status", $status, null);
    $w->setLayout(null);
    $w->out(json_encode($status));
}
function taskAjaxGrouptoType_ALL(Web &$w)
{
    $types = array();
    // split query string into group and assignee
    list($group, $assignee) = preg_split('/_/', $w->request('id'));
    // organise criteria
    $who = $assignee != "" ? $assignee : null;
    $where = "";
    if ($group != "") {
        $where .= "task_group_id = " . $group . " and ";
    }
    $where .= "is_closed = 0";
    // get task types from available task list
    $tasks = $w->Task->getTasks($who, $where);
    if ($tasks) {
        foreach ($tasks as $task) {
            if (!array_key_exists($task->task_type, $types)) {
                $types[$task->task_type] = array($task->getTypeTitle(), $task->task_type);
            }
        }
    }
    if (!$types) {
        $types = array(array("No assigned Tasks", ""));
    }
    // load type dropdown and return
    $tasktypes = Html::select("tasktypes", $types, null);
    $w->setLayout(null);
    $w->out(json_encode($tasktypes));
}
Example #10
0
/**
* Display member and permission infomation
*
* @param <type> $w
*/
function moreInfo_GET(Web &$w)
{
    $option = $w->pathMatch("group_id");
    $w->Admin->navigation($w, $w->Auth->getUser($option['group_id'])->login);
    if ($w->Auth->user()->is_admin || $w->Auth->getRoleForLoginUser($option['group_id'], $w->Auth->user()->id) == "owner") {
        $w->ctx("addMember", Html::box("/admin/groupmember/" . $option['group_id'], "New Member", true));
    }
    $w->ctx("editPermission", Html::b("/admin/permissionedit/" . $option['group_id'], "Edit Permissions"));
    //fill in member table;
    $table = array(array("Name", "Role", "Operations"));
    $groupMembers = $w->Auth->getGroupMembers($option['group_id']);
    if ($groupMembers) {
        foreach ($groupMembers as $groupMember) {
            $line = array();
            $style = $groupMember->role == "owner" ? "<div style=\"color:red;\">" : "<div style=\"color:blue;\">";
            $name = $groupMember->getUser()->is_group == 1 ? $groupMember->getUser()->login : $groupMember->getUser()->getContact()->getFullName();
            $line[] = $style . $name . "</div>";
            $line[] = $style . $groupMember->role . "</div>";
            if ($w->Auth->user()->is_admin || $w->Auth->getRoleForLoginUser($option['group_id'], $w->Auth->user()->id) == "owner") {
                $line[] = Html::a("/admin/memberdelete/" . $option['group_id'] . "/" . $groupMember->id, "Delete", null, null, "Are you sure you want to delete this member?");
            } else {
                $line[] = null;
            }
            $table[] = $line;
        }
    }
    $w->ctx("memberList", Html::table($table, null, "tablesorter", true));
}
Example #11
0
function editworkentry_POST(Web $w)
{
    list($workentry_id) = $w->pathMatch("id");
    if (empty($workentry_id)) {
        $w->error("Missing an ID");
    }
    $we = $w->Bend->getWorkEntryForId($workentry_id);
    if (empty($we)) {
        $w->error("No work entry found for this id: " . $workentry_id);
    }
    $we->fill($_POST);
    if (empty($we->user_id)) {
        $we->user_id = $w->Auth->user()->id;
    }
    // now get the category
    if (!empty($_POST['category_3'])) {
        $we->bend_work_category_id = $_POST['category_3'];
    } else {
        if (!empty($_POST['category_2'])) {
            $we->bend_work_category_id = $_POST['category_2'];
        } else {
            if (!empty($_POST['category_1'])) {
                $we->bend_work_category_id = $_POST['category_1'];
            }
        }
    }
    // TODO check work period, etc.
    $we->update();
    $w->msg("Work hours recorded", "/bend-workhours/list");
}
Example #12
0
function printqueue_GET(Web $w)
{
    $print_folder = FILE_ROOT . "print";
    $path = realpath($print_folder);
    // Check if folder exists
    if ($path === false) {
        // Make print folder (If you specify a full path, use the recursion flag because it seems to crash without it in unix)
        // Other wise you would need to chdir to the parent folder, create and change back to wherever execution currently was at
        mkdir($print_folder, 0777, true);
        $path = realpath($print_folder);
    }
    $exclude = array("THUMBS.db");
    $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
    $table_data = array();
    $table_header = array("Name", "Size", "Date Created", "Actions");
    foreach ($objects as $name => $object) {
        $filename = $object->getFilename();
        // Ignore files starting with '.' and in exclude array
        if ($filename[0] === '.' || in_array($filename, $exclude)) {
            continue;
        }
        $table_data[] = array(Html::a("/uploads/print/" . $filename, $filename), humanReadableBytes($object->getSize()), date("H:i d/m/Y", filectime($name)), Html::box("/admin/printfile?filename=" . urlencode($name), "Print", true) . " " . Html::b("/admin/deleteprintfile?filename=" . urlencode($name), "Delete", "Are you sure you want to remove this file? (This is irreversible)"));
    }
    $w->out(Html::table($table_data, null, "tablesorter", $table_header));
}
function taskAjaxSelectbyTaskGroup_ALL(Web $w)
{
    $p = $w->pathMatch("taskgroup_id");
    $taskgroup = $w->Task->getTaskGroup($p['taskgroup_id']);
    if (empty($taskgroup->id)) {
        return;
    }
    $tasktypes = $taskgroup != "" ? $w->Task->getTaskTypes($taskgroup->task_group_type) : array();
    $priority = $taskgroup != "" ? $w->Task->getTaskPriority($taskgroup->task_group_type) : array();
    $members = $taskgroup != "" ? $w->Task->getMembersBeAssigned($taskgroup->id) : array();
    sort($members);
    $typetitle = $taskgroup != "" ? $taskgroup->getTypeTitle() : "";
    $typedesc = $taskgroup != "" ? $taskgroup->getTypeDescription() : "";
    // if user cannot assign tasks in this group, leave 'first_assignee' blank for owner/member to delegate
    $members = $taskgroup->getCanIAssign() ? $members : array(array("Default", ""));
    // create dropdowns loaded with respective data
    $ttype = Html::select("task_type", $tasktypes, null);
    $prior = Html::select("priority", $priority, null);
    $mem = Html::select("assignee_id", $members, null);
    // first_
    $taskgroup_link = $taskgroup->isOwner($w->Auth->user()) ? "<a href=\"" . $w->localUrl("task-group/viewmembergroup/" . $taskgroup->id) . "\">" . $taskgroup->title . "</a>" : $taskgroup->title;
    $tasktext = "<table style='width: 100%;'>" . "<tr><td class=section colspan=2>Task Group Description</td></tr>" . "<tr><td><b>Task Group</td><td>" . $taskgroup_link . "</td></tr>" . "<tr><td><b>Task Type</b></td><td>" . $typetitle . "</td></tr>" . "<tr valign=top><td><b>Description</b></td><td>" . $typedesc . "</td></tr>" . "</table>";
    // return as array of arrays
    $result = array($ttype, $prior, $mem, $tasktext, Html::select("status", $taskgroup->getTypeStatus(), null, null, null, null));
    $w->setLayout(null);
    $w->out(json_encode($result));
}
function reportAjaxCategorytoType_ALL(Web $w)
{
    $type = array();
    list($category, $module) = preg_split('/_/', $w->request('id'));
    // organise criteria
    $who = $w->session('user_id');
    $where = array();
    if (!empty($module)) {
        $where['report.module'] = $module;
    }
    if (!empty($category)) {
        $where['report.category'] = $category;
    }
    // get report categories from available report list
    $reports = $w->Report->getReportsbyUserWhere($who, $where);
    if ($reports) {
        foreach ($reports as $report) {
            $arrtype = preg_split("/,/", $report->sqltype);
            foreach ($arrtype as $rtype) {
                $rtype = trim($rtype);
                if (!array_key_exists(strtolower($rtype), $type)) {
                    $type[strtolower($rtype)] = array(strtolower($rtype), strtolower($rtype));
                }
            }
        }
    }
    if (empty($type)) {
        $type = array(array("No Reports", ""));
    }
    $w->setLayout(null);
    $w->out(json_encode(Html::select("type", $type)));
}
Example #15
0
function deletereport_ALL(Web &$w)
{
    $p = $w->pathMatch("id");
    // if there is  report ID in the URL ...
    if ($p['id']) {
        // get report details
        $rep = $w->Report->getReportInfo($p['id']);
        // if report exists, delete
        if ($rep) {
            $rep->is_deleted = 1;
            $rep->update();
            // need to check if there is a feed associated with this report
            $feed = $w->Report->getFeedInfobyReportId($rep->id);
            // if feed exists, set is_deleted flag. ie. delete feed as well as report
            if ($feed) {
                $feed->is_deleted = 1;
                $feed->update();
            }
            // return
            $w->msg("Report deleted", "/report/index/");
        } else {
            $w->msg("Report no longer exists?", "/report/index/");
        }
    }
}
Example #16
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);
    }
}
Example #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);
}
Example #18
0
function atfile_GET(Web &$w)
{
    $p = $w->pathMatch("id");
    $id = str_replace(".jpg", "", $p['id']);
    $attachment = $w->service("File")->getAttachment($id);
    $w->sendFile(FILE_ROOT . $attachment->fullpath);
}
Example #19
0
function composer_ALL(Web $w)
{
    echo "<pre>" . file_get_contents(ROOT_PATH . '/log/composer.log') . "</pre>";
    // Collect dependencies
    $dependencies_array = array();
    foreach ($w->modules() as $module) {
        $dependencies = Config::get("{$module}.dependencies");
        if (!empty($dependencies)) {
            $dependencies_array = array_merge($dependencies, $dependencies_array);
        }
    }
    $json_obj = array();
    $json_obj["config"] = array();
    $json_obj["config"]["vendor-dir"] = 'composer/vendor';
    $json_obj["config"]["cache-dir"] = 'composer/cache';
    $json_obj["config"]["bin-dir"] = 'composer/bin';
    $json_obj["require"] = $dependencies_array;
    // Need to change dir so composer can find the json file
    chdir(SYSTEM_PATH);
    // Create the JSON file
    file_put_contents(SYSTEM_PATH . "/composer.json", json_encode($json_obj, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_FORCE_OBJECT));
    //Create the commands
    $input = new ArrayInput(array('command' => 'update', '--prefer-dist' => 'true'));
    $filestream = new StreamOutput(fopen(ROOT_PATH . '/log/composer.log', 'w'));
    //Create the application and run it with the commands
    $application = new Application();
    $exitcode = $application->run($input, $filestream);
    // Change dir back to root
    chdir(ROOT_PATH);
    // This doesn't happen for some reason
    $w->msg("Composer update return exit code " . $exitcode . " (0 is OK)<br/>Check the /log/composer.log for output", "/admin");
}
Example #20
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]);
}
function reportAjaxModuletoCategory_ALL(Web $w)
{
    $category = array();
    $module = $w->request('id');
    // organise criteria
    $who = $w->session('user_id');
    $where = array();
    if ($module != "") {
        $where['report.module'] = $module;
    }
    // get report categories from available report list
    $reports = $w->Report->getReportsbyUserWhere($who, $where);
    if ($reports) {
        foreach ($reports as $report) {
            if (!array_key_exists($report->category, $category)) {
                $category[$report->category] = array($report->getCategoryTitle(), $report->category);
            }
        }
    }
    if (!$category) {
        $category = array(array("No Reports", ""));
    }
    // load Category dropdown and return
    $category = Html::select("category", $category);
    $w->setLayout(null);
    $w->out(json_encode($category));
}
Example #22
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);
}
Example #23
0
function editlookup_POST(Web &$w)
{
    $p = $w->pathMatch("id", "type");
    $err = "";
    if ($_REQUEST['type'] == "") {
        $err = "Please add select a TYPE<br>";
    }
    if ($_REQUEST['code'] == "") {
        $err .= "Please enter a KEY<br>";
    }
    if ($_REQUEST['title'] == "") {
        $err .= "Please enter a VALUE<br>";
    }
    if ($err != "") {
        $w->error($err, "/admin/lookup/?type=" . $p['type']);
    } else {
        $lookup = $w->Admin->getLookupbyId($p['id']);
        if ($lookup) {
            $lookup->fill($_REQUEST);
            $lookup->update();
            $msg = "Lookup Item edited";
        } else {
            $msg = "Could not find item?";
        }
        $w->msg($msg, "/admin/lookup/?type=" . $p['type']);
    }
}
function ajax_getwidgetnames_GET(Web $w)
{
    $module = $w->request("source");
    if (!empty($module)) {
        $names = $w->Widget->getWidgetNamesForModule($module);
        echo json_encode($names);
    }
}
Example #25
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);
}
function taskAjaxSelectbyTable_ALL(Web $w)
{
    $tbl = $_REQUEST['id'];
    // create dropdowns loaded with respective data
    $dbfields = $w->Report->getFieldsinTable($tbl);
    $w->setLayout(null);
    $w->out(json_encode($dbfields));
}
Example #27
0
function logout_GET(Web &$w)
{
    if ($w->Auth->loggedIn()) {
        // Unset all of the session variables.
        $w->sessionDestroy();
    }
    $w->redirect($w->localUrl("/auth/login"));
}
Example #28
0
function edit_POST(Web $w)
{
    $p = $w->pathMatch("id");
    $report_template = !empty($p['id']) ? $w->Report->getReportTemplate($p['id']) : new ReportTemplate($w);
    $report_template->fill($_POST);
    $response = $report_template->insertOrUpdate();
    $w->msg("Report template " . (!empty($p['id']) ? "updated" : "created"), "/report/edit/{$report_template->report_id}#templates");
}
Example #29
0
function callchannel_ALL(Web $w)
{
    $w->setLayout(null);
    $p = $w->pathMatch("id");
    $id = $p["id"];
    $channel = $w->Channel->getEmailChannel($id);
    $channel->doJob();
}
Example #30
0
function groupedit_POST(Web $w)
{
    $option = $w->pathMatch("group_id");
    $user = $w->Auth->getUser($option['group_id']);
    $user->login = $_REQUEST['title'];
    $user->update();
    $w->msg("Group info updated!", "/admin/groups");
}