public function getContents() { User::log("Logged out"); $_SESSION = array(); header("Location: " . Application::getLink("/")); Application::$template = "login.tpl"; return "You have been logged out."; }
/** * Called recursively by the side_menu::generate() method for purposes of * generating a menu on the side. * * @param $menu * @param $level * @return unknown_type */ private function doMenu($menu, $level = 0) { $this->id++; if (!is_array($menu)) { return; } $ret = "<ul class='menu " . ($level == 0 ? "root-menu" : "sub-menu") . " menu-level-{$level}' id='menu-{$this->id}'>"; foreach ($menu as $item) { $nuId = $this->id + 1; $path = count($item["children"]) > 0 ? "javascript:" : Application::getLink($item["path"]); $extra = count($item["children"]) > 0 ? "onclick='expand(\"menu-{$nuId}\")' style='font-weight:bold'" : ""; $ret = $ret . "<li><a href='{$path}' {$extra}>{$item["title"]}</a>"; if (count($item["children"] > 0)) { $ret = $ret . $this->doMenu($item["children"], $level + 1); } $ret = $ret . "</li>"; } $ret = $ret . "</ul>"; return $ret; }
/** * A callback function which checks the validity of passwords on the form. * It checks to ensure that the right user is logging in with the right * password. * * @param $data * @param $form * @param $callback_pass * @return unknown_type */ public static function callback($data, $form, $callback_pass = null) { $user = Model::load(".users"); $userData = $user->get(array("conditions" => "user_name='{$data["username"]}'"), Model::MODE_ASSOC, false, false); if (count($userData) == 0) { $form->addError("Please check your username or password"); return true; } else { if ($userData[0]["role_id"] == null) { $form->addError("Sorry! your account has no role attached!"); return true; } else { if (User::getPermission("can_log_in_to_web", $userData[0]["role_id"])) { $home = Application::getLink("/"); /* Verify the password of the user or check if the user is logging in * for the first time. */ if ($userData[0]["password"] == md5($data["password"]) || $userData[0]["user_status"] == 2) { switch ($userData[0]["user_status"]) { case "0": $form->addError("Your account is currently inactive" . "please contact the system administrator."); return true; break; case "1": $_SESSION["logged_in"] = true; $_SESSION["user_id"] = $userData[0]["user_id"]; $_SESSION["user_name"] = $userData[0]["user_name"]; $_SESSION["user_firstname"] = $userData[0]["first_name"]; $_SESSION["user_lastname"] = $userData[0]["last_name"]; $_SESSION["read_only"] = $userData[0]['read_only']; $_SESSION["role_id"] = $userData[0]["role_id"]; $_SESSION['branch_id'] = $userData[0]['branch_id']; $_SESSION["department_id"] = $userData[0]['department_id']; Sessions::bindUser($userData[0]['user_id']); User::log("Logged in"); Application::redirect($home); break; case "2": $_SESSION["logged_in"] = true; $_SESSION["user_id"] = $userData[0]["user_id"]; $_SESSION["user_name"] = $userData[0]["user_name"]; $_SESSION["role_id"] = $userData[0]["role_id"]; $_SESSION["department_id"] = $userData[0]['department_id']; $_SESSION["user_firstname"] = $userData[0]["first_name"]; $_SESSION["user_lastname"] = $userData[0]["last_name"]; $_SESSION['branch_id'] = $userData[0]['branch_id']; $_SESSION["user_mode"] = "2"; Sessions::bindUser($userData[0]['user_id']); User::log("Logged in for first time"); Application::redirect($home); break; } } else { $form->addError("Please check your username or password"); return true; } } else { $form->addError("You are not allowed to log in from this terminal"); return true; } } } }
private static function getHomeRedirect() { return Application::getLink("/"); }
/** * Returns a form to be used to filter the report. This method analyses the * XML file and uses the fields specified in there to generate a very form * which allows you to define filter for the form. The form generated also * gives you options to sort and group the reports. * @return Form */ public function getForm() { $this->initializeForm(); $filters = array(); $fieldInfos = array(); $tables = $this->xml->xpath("/rapi:report/rapi:table"); /// Filters and sorting. foreach ($tables as $table) { $numConcatFields = 0; $fields = $table->xpath("/rapi:report/rapi:table[@name='{$table["name"]}']/rapi:fields/rapi:field"); $labels = $table->xpath("/rapi:report/rapi:table[@name='{$table["name"]}']/rapi:fields/rapi:field/@label"); $filters = new TableLayout(count($fields) + 1, 5); $filters->add(Element::create("Label", "Field")->addCssClass("header-label"), 0, 0)->add(Element::create("Label", "Options")->addCssClass("header-label"), 0, 1)->add(Element::create("Label", "Exclude")->addCssClass("header-label"), 0, 4)->resetCssClasses()->addCssClass("filter-table")->setRenderer("default"); $sortingField = new SelectionList("Sorting Field", "{$table["name"]}_sorting_field"); $grouping1 = new SelectionList(); $i = 1; foreach ($fields as $key => $field) { if (isset($field["labelsField"])) { continue; } if (count(explode(",", (string) $field)) == 1) { $fieldInfo = Model::resolvePath((string) $field); $model = Model::load($fieldInfo["model"]); $fieldName = $fieldInfo["field"]; $fieldInfo = $model->getFields(array($fieldName)); $fieldInfo = $fieldInfo[0]; $fields[$key] = (string) $field; $sortingField->addOption(str_replace("\\n", " ", $fieldInfo["label"]), $model->getDatabase() . "." . $fieldInfo["name"]); $grouping1->addOption(str_replace("\\n", " ", $field["label"]), $field); if (array_search($model->getKeyField(), $this->referencedFields) === false || $fieldInfo["type"] == "double" || $fieldInfo["type"] == "date") { switch ($fieldInfo["type"]) { case "integer": case "double": $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Equals", "EQUALS")->addOption("Greater Than", "GREATER")->addOption("Less Than", "LESS")->addOption("Between", "BETWEEN")->setValue("BETWEEN"), $i, 1)->add(Element::create("TextField", "", "{$table["name"]}.{$fieldInfo["name"]}_start_value")->setAsNumeric(), $i, 2)->add(Element::create("TextField", "", "{$table["name"]}.{$fieldInfo["name"]}_end_value")->setAsNumeric(), $i, 3); //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4); break; case "date": case "datetime": $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Before", "LESS")->addOption("After", "GREATER")->addOption("On", "EQUALS")->addOption("Between", "BETWEEN")->setValue("BETWEEN"), $i, 1)->add(Element::create("DateField", "", "{$table["name"]}.{$fieldInfo["name"]}_start_date")->setId("{$table["name"]}_{$fieldInfo["name"]}_start_date"), $i, 2)->add(Element::create("DateField", "", "{$table["name"]}.{$fieldInfo["name"]}_end_date")->setId("{$table["name"]}_{$fieldInfo["name"]}_end_date"), $i, 3); //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4); break; case "enum": $enum_list = new SelectionList("", "{$table["name"]}.{$fieldInfo["name"]}_value"); $enum_list->setMultiple(true); foreach ($fieldInfo["options"] as $value => $label) { $enum_list->addOption($label, $value); } if (!isset($field["value"])) { $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Is any of", "INCLUDE")->addOption("Is none of", "EXCLUDE")->setValue("INCLUDE"), $i, 1)->add($enum_list, $i, 2); } //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4); break; case "string": case "text": $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Is exactly", "EXACTLY")->addOption("Contains", "CONTAINS")->setValue("CONTAINS"), $i, 1)->add(Element::create("TextField", "", "{$table["name"]}.{$fieldInfo["name"]}_value"), $i, 2); //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4); break; } if (isset($field["hide"])) { $filters->add(Element::create("HiddenField", "{$table["name"]}.{$fieldInfo["name"]}_ignore", "1"), $i, 4); } else { $filters->add(Element::create("Checkbox", "", "{$table["name"]}.{$fieldInfo["name"]}_ignore", "", "1"), $i, 4); } } else { $enum_list = new ModelSearchField(); $enum_list->setName("{$table["name"]}.{$fieldInfo["name"]}_value"); $enum_list->setModel($model, $fieldInfo["name"]); $enum_list->addSearchField($fieldInfo["name"]); $enum_list->boldFirst = false; $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Is any of", "IS_ANY_OF")->addOption("Is none of", "IS_NONE_OF")->setValue("IS_ANY_OF"), $i, 1)->add(Element::create("MultiFields")->setTemplate($enum_list), $i, 2)->add(Element::create("Checkbox", "", "{$table["name"]}.{$fieldInfo["name"]}_ignore", "", "1"), $i, 4); } } else { $grouping1->addOption(str_replace("\\n", " ", $field["label"]), $field); $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}_concat_{$numConcatFields}_option")->addOption("Is exactly", "EXACTLY")->addOption("Contains", "CONTAINS")->setValue("CONTAINS"), $i, 1)->add(Element::create("TextField", "", "{$table["name"]}_concat_{$numConcatFields}_value"), $i, 2)->add(Element::create("Checkbox", "", "{$table["name"]}_concat_{$numConcatFields}_ignore", "", "1"), $i, 4); $numConcatFields++; } $i++; } $grouping1->setName("{$table["name"]}_grouping[]")->setLabel("Grouping Field 1"); $g1Paging = new Checkbox("Start on a new page", "grouping_1_newpage", "", "1"); $g1Logo = new Checkbox("Repeat Logos", "grouping_1_logo", "", "1"); $g1Summarize = new Checkbox("Summarize", "grouping_1_summary", "", "1"); $grouping2 = clone $grouping1; $grouping2->setName("{$table["name"]}_grouping[]")->setLabel("Grouping Field 2"); $g2Paging = new Checkbox("Start on a new page", "grouping_2_newpage", "", "1"); $g2Logo = new Checkbox("Repeat Logos", "grouping_2_logo", "", "1"); $grouping3 = clone $grouping1; $grouping3->setName("{$table["name"]}_grouping[]")->setLabel("Grouping Field 3"); $g3Paging = new Checkbox("Start on a new page", "grouping_3_newpage", "", "1"); $g3Logo = new Checkbox("Repeat Logos", "grouping_3_logo", "", "1"); $sortingField->setLabel("Sorting Field"); $sortingField->setName($table["name"] . "_sorting"); $groupingTable = new TableLayout(3, 4); $groupingTable->add($grouping1, 0, 0); $groupingTable->add($g1Paging, 0, 1); $groupingTable->add($g1Logo, 0, 2); $groupingTable->add($g1Summarize, 0, 3); $groupingTable->add($grouping2, 1, 0); /*$groupingTable->add($g2Paging, 1, 1); $groupingTable->add($g2Logo, 1, 2);*/ $groupingTable->add($grouping3, 2, 0); $container = new FieldSet($table["name"]); $container->add(Element::create("FieldSet", "Filters")->add($filters)->setId("table_{$table['name']}"), Element::create("FieldSet", "Sorting * Limiting")->add($sortingField, Element::create("SelectionList", "Direction", "{$table["name"]}.sorting_direction")->addOption("Ascending", "ASC")->addOption("Descending", "DESC"), Element::create('TextField', 'Limit', "{$table['name']}.limit")->setAsNumeric()), Element::create("FieldSet", "Grouping")->add($groupingTable)); $sortingField->setName($table["name"] . "_sorting"); $this->form->add($container); } $this->form->setSubmitValue("Generate"); $this->form->addAttribute("action", Application::getLink($this->path . "/generate")); $this->form->addAttribute("target", "blank"); return $this->form; }
/** * Initializes a form for reports. The form generate already contains options * which are standard to all reports. The initialized form is accessible * through the ReportController::form variable. */ protected function initializeForm() { $this->form = new Form(); $this->form->add(Element::create("FieldSet", "Report Format")->add(Element::create("SelectionList", "File Format", "report_format")->addOption("Hypertext Markup Language (HTML)", "html")->addOption("Portable Document Format (PDF)", "pdf")->addOption("Microsoft Excel (XLS)", "xls")->addOption("Microsoft Word (DOC)", "doc")->setRequired(true)->setValue("pdf"), Element::create("SelectionList", "Page Orientation", "page_orientation")->addOption("Landscape", "L")->addOption("Portrait", "P")->setValue("L"), Element::create("SelectionList", "Paper Size", "paper_size")->addOption("A4", "A4")->addOption("A3", "A3")->setValue("A4"))->setId("report_formats")->addAttribute("style", "width:50%")); $this->form->setSubmitValue("Generate"); $this->form->addAttribute("action", Application::getLink($this->path . "/generate")); $this->form->addAttribute("target", "blank"); }
public function render($headers = true) { global $redirectedPackage; $results = $this->tableData; $this->fields = $results["fieldInfos"]; foreach ($this->fields as $field) { if ($field["type"] == "number" || $field["type"] == "double" || $field["type"] == "integer") { $this->headerParams[$field["name"]]["type"] = "number"; } } $this->headers = $results["headers"]; array_shift($this->headers); if ($headers === true) { $table = $this->renderHeader(); } if ($this->useAjax) { $table .= "<tr>\n <td align='center' colspan='" . count($this->headers) . "'>\n <img style='margin:80px' src='/" . Application::getLink(Application::getWyfHome("tapi/images/loading-image-big.gif")) . "' />\n </td></tr>"; } else { $this->data = $results["data"]; $table .= parent::render(false); } if ($headers === true) { $table .= $this->renderFooter(); } if ($this->useAjax) { $this->params['redirected_package'] = $redirectedPackage; $table .= "<div id='{$this->name}-operations'></div>\n <script type='text/javascript'>\n wyf.tapi.addTable('{$this->name}',(" . json_encode($this->params) . "));\n var externalConditions = [];\n var externalBoundData = [];\n function {$this->name}Search()\n {\n var conditions = '';\n var boundData = [];\n {$this->searchScript}\n wyf.tapi.tables['{$this->name}'].filter = conditions;\n wyf.tapi.tables['{$this->name}'].bind = boundData;\n if(externalConditions['{$this->name}'])\n {\n wyf.tapi.tables['{$this->name}'].filter += ((conditions != '' ?' AND ':'') + externalConditions['{$this->name}']);\n wyf.tapi.tables['{$this->name}'].bind = boundData.concat(externalBoundData);\n }\n wyf.tapi.tables['{$this->name}'].page = 0;\n wyf.tapi.render(wyf.tapi.tables['{$this->name}']);\n }\n </script>"; } return $table; }
$i++; } $item = str_replace("_", " ", $item); $item = ucwords($item); $top_menu .= "<a href='" . Application::getLink($link) . "'><span>{$item}</span></a>"; } Application::$templateEngine->assign('top_menu', $top_menu); } } } // Log the route into the audit trail if it is enabled if ($_SESSION['logged_in'] == true && $_GET['q'] != 'system/api/table' && ENABLE_AUDIT_TRAILS === true) { $data = json_encode(array('route' => $_GET['q'], 'request' => $_REQUEST, 'get' => $_GET, 'post' => $_POST)); if (class_exists("SystemAuditTrailModel", false) && ENABLE_ROUTING_TRAILS === true) { SystemAuditTrailModel::log(array('item_id' => '0', 'item_type' => 'routing_activity', 'description' => "Accessed [{$_GET['q']}]", 'type' => SystemAuditTrailModel::AUDIT_TYPE_ROUTING, 'data' => $data)); } } // Load the styleseets and the javascripts if ($GLOBALS['fapi_stylesheet'] === false) { Application::preAddStylesheet("css/fapi.css", Application::getWyfHome("fapi/")); } else { Application::preAddStylesheet($GLOBALS['fapi_stylesheet']); } Application::preAddStylesheet("kalendae/kalendae.css", Application::getWyfHome('assets/js/')); Application::preAddStylesheet("css/main.css"); Application::addStylesheet('css/rapi.css', Application::getWyfHome('rapi/')); Application::addJavaScript(Application::getLink(Application::getWyfHome("fapi/js/fapi.js"))); Application::addJavaScript(Application::getLink(Application::getWyfHome("assets/js/jquery.js"))); Application::addJavaScript(Application::getLink(Application::getWyfHome("assets/js/kalendae/kalendae.js"))); // Blast the HTML code to the browser! Application::render();
$item = $top_menu_items[$i]; $link .= "/" . $item; while (is_numeric($top_menu_items[$i + 1])) { $link .= "/" . $top_menu_items[$i + 1]; $i++; } $item = str_replace("_", " ", $item); $item = ucwords($item); $top_menu .= " <a href='" . Application::getLink($link) . "'><span>{$item}</span></a>"; } $t->assign('top_menu', $top_menu); } } // Log the route into the audit trail if it is enabled if ($_SESSION['logged_in'] == true && $_GET['q'] != 'system/api/table' && ENABLE_AUDIT_TRAILS === true) { $data = json_encode(array('route' => $_GET['q'], 'request' => $_REQUEST, 'get' => $_GET, 'post' => $_POST)); if (class_exists("SystemAuditTrailModel", false) && ENABLE_ROUTING_TRAILS === true) { SystemAuditTrailModel::log(array('item_id' => '0', 'item_type' => 'routing_activity', 'description' => "Accessed [{$_GET['q']}]", 'type' => SystemAuditTrailModel::AUDIT_TYPE_ROUTING, 'data' => $data)); } } // Load the styleseets and the javascripts Application::addStylesheet("css/fapi.css", "lib/fapi/"); Application::addStylesheet("css/main.css"); Application::addJavaScript(Application::getLink("/lib/fapi/js/fapi.js")); Application::addJavaScript(Application::getLink("/lib/js/jquery.js")); Application::addJavaScript(Application::getLink("/lib/js/jquery-ui.js")); Application::addJavaScript(Application::getLink("/lib/js/json2.js")); // Blast the HTML code to the browser! Application::$site_name = Application::$config['name']; Application::render(); }