public static function simplePaginator($totalrows, $param_obj = "") { if (is_array($totalrows)) { $totalrows = 1; } $accelJS = AccelJS::findThis(); $curpage = isset($_REQUEST["page"]) ? $_REQUEST["page"] : 1; $default_limit = isset($param_obj['default_limit']) ? $param_obj['default_limit'] : 50; $numrows = isset($_REQUEST["limit"]) ? $_REQUEST["limit"] : $default_limit; $accelJS->js("\n function select_new_pagination(reset_page,searchStr){\n\n var default_limit = {$default_limit};\n var search = unescape(window.location.search);\n var path = unescape(window.location.pathname);\n\n page_num = reset_page == 1 ? 1 : \$('#curpage_select').val();\n\n search = search.replace(\"?\",\"\");\n queryArr = search.split(\"&\");\n\n for (var i = 0;i < queryArr.length;i++) {\n\n if (queryArr[i].indexOf(\"limit\") >= 0){\n queryArr.splice(i,1);\n\n }\n\n if ( queryArr[i] != undefined ){\n if (queryArr[i].indexOf(\"page\") >= 0){\n queryArr.splice(i,1);\n\n }\n }\n\n if ( queryArr[i] != undefined ){\n if (queryArr[i].indexOf(\"search_string\") >= 0){\n queryArr.splice(i,1);\n }\n }\n\n }\n\n if (page_num == undefined) page_num = 1;\n\n if (\$('#numrows_select').length > 0){\n page_limit = \$('#numrows_select').val();\n }else {\n page_limit = default_limit;\n }\n\n\n if (queryArr.length > 0){\n newSearch = \"?\" + queryArr.join(\"&\") + \"&limit=\" + page_limit + \"&page=\" + page_num;\n }else {\n\n newSearch = \"?limit=\" + page_limit + \"&page=\" + page_num;\n\n }\n\n\n searchStr = encodeURI( searchStr );\n\n if (searchStr.length > 0) newSearch += \"&search_string=\" + searchStr;\n\n window.location = path + newSearch;\n }\n "); $accelJS->ready("\n \$(\"#numrows_select\").change( function(){\n select_new_pagination(1,'');\n });\n\n \$(\"#curpage_select\").change( function(){\n select_new_pagination(0,'');\n });\n "); if ($numrows == "All") { $numrows = $totalrows; } $numrows_sel_text = isset($param_obj['numrows_key']) ? $param_obj['numrows_key'] : "Rows per page: "; $curpage_sel_text = "<b>Jump to page:</b>"; $start = $curpage * $numrows + 1; $end = $start + $numrows; if ($end > $totalrows) { $end = $totalrows; } if ($numrows > 0) { $total_pages = ceil($totalrows / $numrows); } else { $total_pages = 1; } for ($i = 1; $i <= $total_pages; $i++) { $page_list[] = $i; } if ($numrows == $totalrows && $totalrows > 100) { $_numrows = "All"; } else { $_numrows = $numrows; } // if they've passed in a default_limit we need it in the rows selector $nr_selectorArray = array(2, 5, 10, 25, 50, 100); if ($totalrows < 1000) { $nr_selectorArray[] = 'All'; } if ($param_obj['default_limit'] && !in_array($param_obj['default_limit'], $nr_selectorArray)) { array_unshift($nr_selectorArray, $param_obj['default_limit']); } $nr_selector = self::dropDownFromArray($nr_selectorArray, "numrows", $_numrows); $cp_selector = self::dropDownFromArray($page_list, "curpage", $curpage); $strip_link = $_SERVER["REQUEST_URI"]; if (strpos($_SERVER["REQUEST_URI"], '?page') !== false) { $thisSeparator = '?'; } elseif (strpos($_SERVER["REQUEST_URI"], '?') === false) { $thisSeparator = '?'; } else { $thisSeparator = '&'; } $strip_link = str_replace("&page=" . $_GET["page"], "", $strip_link); $strip_link = str_replace("?page=" . $_GET["page"], "", $strip_link); $prev_count = $curpage - 1 > 0 ? $curpage - 1 : 1; $next_count = $curpage + 1 <= $total_pages ? $curpage + 1 : $total_pages; $prevLink = "<a href='{$strip_link}{$thisSeparator}page={$prev_count}'>« Prev</a>"; $nextLink = "<a href='{$strip_link}{$thisSeparator}page={$next_count}'>Next »</a>"; $searchTitle = isset($param_obj["searchTitle"]) ? $param_obj["searchTitle"] : "Search:"; $searchBox = ""; if (isset($param_obj['searchBox'])) { $jscr = "\n \$('#search_now').click ( function(){\n search = \$('#searchBox').val();\n select_new_pagination(0,search);\n });\n\n \$('#searchBox').keyup(function(e) {\n if(e.keyCode == 13) {\n search = \$('#searchBox').val();\n select_new_pagination(0,search);\n }\n })\n"; AccelJS::findThis()->ready($jscr); $param_obj["searchBox"]["post"] = array('searchBox' => $_REQUEST["search_string"]); $searchBox = FormBuilder::quickTextField("searchBox", $param_obj['searchBox']); $searchBtn = "<img id='search_now' style='cursor:pointer; margin:0px; padding:0px;' src='" . self::adminIconSrc('find') . "' />"; $searchBox = "<div style='float:left;'><table cellpadding='2px' cellspacing='2px' border='0'>\n <tr><td style='font-weight:bold;'>{$searchTitle}</td><td>{$searchBox}</td><td>{$searchBtn}</td></tr>\n </table></div>"; } elseif (isset($param_obj['autoCompleter'])) { $jscr = "\n\n \$('#search_now').click ( function(){\n search = \$('#searchBox_ac').val();\n select_new_pagination(0,search);\n });"; AccelJS::findThis()->ready($jscr); $searchBtn = " <span style='cursor:pointer;' id='search_now'>" . FormBuilder::adminIcon('find', 'Query Results') . '</span>'; $searchBox = FormBuilder::autoCompleter(null, "searchBox", $param_obj['autoCompleter']); $searchBox = "<div style='float:left; padding-left:10px'><b>{$searchTitle}</b> {$searchBox} {$searchBtn}</div>"; } elseif (isset($param_obj['dropdown'])) { $jscr = "\n\n \$('#search_now').click ( function(){\n search = \$('#searchBox_select').val();\n select_new_pagination(0,search);\n });"; AccelJS::findThis()->ready($jscr); $search_str = $param_obj['dropdown']; $arr = $param_obj["dropdownArr"]; $searchBtn = " <span style='cursor:pointer;' id='search_now'>" . FormBuilder::adminIcon('find', 'Query Results') . '</span>'; $searchBox = self::dropDownFromAssocArray($arr, "searchBox"); $searchBox = "<div style='float:left; padding-left:10px'><b>{$search_str}</b> {$searchBox} {$searchBtn}</div>"; } $out = "<div style='position:relative;padding:8px; border-bottom:1px solid #000'>\n\n <div style='float:left; margin-right:10px;'>{$numrows_sel_text} {$nr_selector}</div>\n\n {$searchBox}\n\n <div style='right:0px; position:absolute'>{$prevLink} {$curpage_sel_text} {$cp_selector} {$nextLink}</div>\n <br style='clear:both'/>\n </div>"; $row_start = ($curpage - 1) * $numrows + 1; //$this->row_end = $this->row_start + $this->num_results_displayed; $result["display"] = $out; $result["displayParts"]["rowSelector"] = $nr_selector; $result["displayParts"]["searchBox"] = $searchBox; $result["displayParts"]["prevLink"] = $prevLink; $result["displayParts"]["nextLink"] = $nextLink; $result["displayParts"]["pageSelector"] = $cp_selector; $result["curpage"] = $curpage - 1; $result["numrows"] = $numrows; $result["rowstart"] = $row_start; return $result; }
public static function findThis() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
public function accelJs() { return AccelJS::findThis(); }
public static function action_admin_footer() { echo AccelJS::findThis()->getHtml(); }
public function agreementCheckbox($label, $agreementText, $errorText = NULL) { if (is_null($errorText)) { $errorText = "You must agree before continuing."; } $input = "<input type='checkbox' name='agreementText' /> <span id='agreement_text'>" . $agreementText . "</span>"; $this->accelJs()->ready("\$('input[name=agreementText]').parents('form:first').find('input[type=submit]').click(function(){\n\t\t\tif(\$(this).closest('form').find('input[name=agreementText]:not(:checked)').length > 0){\n\t\t\t\talert('" . AccelJS::escape($errorText) . "');\n\t\t\t\treturn false;\n\t\t\t} else {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t});"); return self::fieldRow($label, $input, array('required' => true)); }