function createSelectorFromListFile($file) { $list = ""; $data = ""; if (file_exists($file)) { $data = file_get_contents($file); } elseif (defined("APPROOT") && defined("APPS_MISC_FOLDER") && file_exists(APPROOT . APPS_MISC_FOLDER . $file)) { $file = APPROOT . APPS_MISC_FOLDER . $file; $data = file_get_contents($file); } elseif (file_exists(ROOT . MISC_FOLDER . $file)) { $file = ROOT . MISC_FOLDER . $file; $data = file_get_contents($file); } else { return ""; } if (strlen($data) > 0) { $data = explode("\n", $data); foreach ($data as $a => $b) { if (strlen($b) > 0 && strpos($b, "#") !== 0) { if (strpos($b, "=") > 0) { $e = explode("=", $b); $e1 = $e[0]; $e2 = $e[1]; echo "<option value='{$e2}'>" . _ling($e1) . "</option>"; } else { echo "<option value='{$b}'>" . _ling($b) . "</option>"; } } } } return $list; }
function createSelectorFromXML($file, $xpath = "//option") { //$level=0,//$attribute="",$value="" if (!file_exists($file)) { return "Error:File Not Found"; return; } $xml = simplexml_load_file($file); $array = array(); $s = ""; if (strlen($xpath) <= 0) { $array = _processXMLNode($xml->children()); } else { $result = $xml->xpath($xpath); if ($result != null) { while (list(, $node) = each($result)) { //$arr=$node->attributes(); //$s.='$xpath: ',$node,"\n"; $a = _parseNode($node); $array[sizeof($array)] = $a; } } } for ($i = 0; $i < sizeof($array); $i++) { //$s.=$array[$i]['name']; $s .= "<option "; if (isset($array[$i]['value'])) { $s .= "value='" . $array[$i]['value'] . "'"; } if (isset($array[$i]['class'])) { $s .= "value='" . $array[$i]['class'] . "'"; } $s .= " >"; $s .= _ling($array[$i]['name']); $s .= "</option>"; } return $s; }
function generateTable(LogiksData $ld, $searchQ = "", $paramTags = array("border" => "1", "cellspacing" => "0", "cellpadding" => "0", "width" => "100%", "height" => "100%", "style" => ""), $titleCol = "title", $printHeader = true) { $html = ""; if ($paramTags !== null) { $html .= "<table " . parseTagParams($paramTags) . ">"; } if ($searchQ && is_string($searchQ) && strlen($searchQ) > 0) { $data = $ld->search($searchQ); } else { $data = $ld->dump(); } if ($printHeader && isset($data[0])) { $html .= "<thead><tr>"; foreach ($data[0] as $key => $value) { $html .= "<th class='{$key}' data-col='{$key}'>" . _ling($key) . "</th>"; } $html .= "</tr></thead>"; } if ($printHeader) { $html .= "<tbody>"; } foreach ($data as $key => $value) { if (is_array($value)) { $html .= "<tr data-key='{$key}'>"; foreach ($value as $a => $b) { if (is_array($b)) { $title = ""; if (is_array($titleCol)) { foreach ($titleCol as $nm) { if (isset($b[$nm])) { $title = $b[$nm]; break; } } } else { if (isset($b[$titleCol])) { $title = $b[$titleCol]; } } $bx = flatternArray($b); $bx = str_replace("%20", "_", http_build_query($bx, " ", " ", PHP_QUERY_RFC3986)); $html .= "<td class='{$a}' data-col='{$a}' {$bx}>" . _ling($title) . "</td>"; } else { $html .= "<td class='{$a}' data-col='{$a}'>" . _ling($b) . "</td>"; } } $html .= "</tr>"; } else { $html .= "<tr><td colspan=10000>"; $html .= _ling($value); $html .= "</td></tr>"; } } if ($printHeader) { $html .= "</tbody>"; } if ($paramTags !== null) { $html .= "</table>"; } return $html; }
function printSQLResult($result, $dataType = "json", $params = array(), $msg = "", $autoLing = true, $maxTextLength = 0) { if ($result == null || is_bool($result)) { $responce->MSG = $msg; header("Content-type: application/json"); echo json_encode($responce); return; } if ($dataType == "json") { if (isset($params["page"])) { $responce->page = intval($params["page"]); } if (isset($params["total"])) { $responce->total = intval($params["total"]); } if (isset($params["records"])) { $responce->records = intval($params["records"]); } //if(isset($params["limit"])) $responce->limit =intval($params["limit"]); $i = 0; //while($row = mysql_fetch_array($result,MYSQL_NUM)) {//MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH mysql_fetch_array while ($row = _db()->fetchData($result, "array", MYSQL_NUM)) { //MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH $responce->rows[$i]['id'] = $row[0]; $responce->rows[$i]['cell'] = array(); $c = 0; foreach ($row as $a => $b) { //if(is_numeric($a)) continue; if :: MYSQL_BOTH $type = mysql_field_type($result, $c); if (strlen($b) > 0) { if ($type == "date") { $df = str_replace("yy", "Y", getConfig("DATE_FORMAT")); $b = _date($b, "Y/m/d", $df); $bT = _date("0000-00-00", "Y/m/d", $df); if ($b == $bT) { $b = ""; } } elseif ($type == "time") { $dt = str_replace("m", "i", getConfig("TIME_FORMAT")); $b = _time($b); $bT = _time("00:00:00", "H:i:s", $dt); if ($b == $bT) { $b = ""; } } elseif ($type == "datetime") { $df = str_replace("yy", "Y", getConfig("DATE_FORMAT")); $dt = str_replace("m", "i", getConfig("TIME_FORMAT")); $ss = explode(" ", $b); $s0 = _date($ss[0], "Y/m/d", $df); if (isset($ss[1])) { $s1 = _time($ss[1]); } else { $s1 = ""; } $b = "{$s0} {$s1}"; $bT = _date("0000-00-00", "Y/m/d", $df); $bT .= " " . _time("00:00:00", "H:i:s", $dt); if ($b == $bT) { $b = ""; } } elseif ($type == "blob") { if ($maxTextLength > 0 && strlen($b) > $maxTextLength) { $b = substr($b, 0, 200) . "..."; } else { $b = stripslashes($b); } $b = htmlentities($b); //str_replace('"',"\\'",$b)); } else { if ($autoLing) { $b = _ling($b, true); } } } array_push($responce->rows[$i]['cell'], $b); $c++; } $i++; } $responce->MSG = $msg; header("Content-type: application/json"); echo json_encode($responce); } elseif ($dataType == "xml") { if (stristr($GLOBALS['LOGIKS']["_SERVER"]["HTTP_ACCEPT"], "application/xhtml+xml")) { header("Content-type: application/xhtml+xml;charset=utf-8"); } else { header("Content-type: text/xml;charset=utf-8"); } $et = ">"; $s = "<?xml version='1.0' encoding='utf-8'?{$et}\n"; $s .= "<rows>"; $s .= "<page>" . $page . "</page>"; $s .= "<total>" . $total_pages . "</total>"; $s .= "<records>" . $count . "</records>"; //while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { while ($row = _db()->fetchData($result)) { $s .= "<row id='" . $row[id] . "'>"; $i = 0; foreach ($row as $a => $b) { $type = mysql_field_type($result, $i); $length = mysql_field_len($result, $i); if ($type == "date") { if (strlen($b) > 0) { $df = str_replace("yy", "Y", getConfig("DATE_FORMAT")); $b = _date($b, "Y/m/d", $df); $bT = _date("0000-00-00", "Y/m/d", $df); if ($b == $bT) { $b = ""; } } if (strlen($b) > 0) { $s .= "<cell><![CDATA[" . $b . "]]></cell>"; } } elseif ($type == "string" && $length > 5) { if ($autoLing) { $b = _ling($b); } if (strlen($b) > 0) { $s .= "<cell><![CDATA[" . $b . "]]></cell>"; } else { $s .= "<cell></cell>"; } } else { if ($autoLing) { $b = _ling($b); } $s .= "<cell>" . $b . "</cell>"; } $i++; } $s .= "</row>"; } $s .= "</rows>"; echo $s; } elseif ($dataType == "html") { if (isset($params["withheader"])) { $withheader = $params["withheader"]; } else { $withheader = "false"; } if (isset($params["multiselect"])) { $multiselect = $params["multiselect"]; } else { $multiselect = "false"; } if ($withheader == "true" || $withheader == 1) { $withheader = true; } else { $withheader = false; } if ($multiselect == "true" || $multiselect == 1) { $multiselect = true; } else { $multiselect = false; } $header = ""; $body = ""; if ($withheader) { $header .= "<thead>"; $header .= "<tr class='tblheader'>"; if ($multiselect) { $header .= "<td width=40px> -- </td>"; } while ($i < mysql_num_fields($result)) { $meta = mysql_fetch_field($result, $i); if ($meta) { $t = str_replace("_", " ", $meta->name); $t = ucwords($t); $header .= "<td align=center>{$t}</td>"; } else { $header .= "<td> </td>"; } $i++; } $header .= "</tr>"; $header .= "</thead>"; } $body .= "<tbody>"; //while($row = mysql_fetch_array($result,MYSQL_NUM)) {//MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH while ($row = _db()->fetchData($result, "array", MYSQL_NUM)) { //MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH $body .= "<tr id='ROW_" . $row[0] . "'>"; if ($multiselect) { $body .= "<td align=center><input type='checkbox' rel='" . $row[0] . "' row='ROW_" . $row[0] . "' /></td>"; } $c = 0; foreach ($row as $a => $b) { $meta = mysql_fetch_field($result, $c); $type = $meta->type; $name = $meta->name; $tbl = $meta->table; if ($type == "date") { if (strlen($b) > 0) { $df = str_replace("yy", "Y", getConfig("DATE_FORMAT")); $b = _date($b, "Y/m/d", $df); $bT = _date("0000-00-00", "Y/m/d", $df); if ($b == $bT) { $b = ""; } } } elseif ($autoLing) { $b = _ling($b); } if ($meta->primary_key) { $body .= "<td col='{$name}' class='serial_col'>{$b}</td>"; } else { if ($type == "date") { if ($b == "NA") { $body .= "<td col='{$name}' class='calerroricon' > </td>"; } else { $body .= "<td col='{$name}' align=center>{$b}</td>"; } } elseif ($type == "int" || $type == "float" || $type == "double") { $body .= "<td col='{$name}' align=right>{$b}</td>"; } elseif ($type == "bool" || $type == "boolean") { $body .= "<td col='{$name}' align=center>{$b}</td>"; } elseif ($type == "blob") { $body .= "<td col='{$name}' class='blobicon' onclick=\"viewBlobData('{$name}','{$tbl}')\"> </td>"; } else { $body .= "<td col='{$name}'>{$b}</td>"; } } $c++; } $body .= "</tr>"; } $body .= "</tbody>"; echo "<table width=100%>{$header} {$body}</table>"; } else { printArray($data); } }
$oldPages = explode("/", $_COOKIE['PAGEPATH']); if (in_array($pages[$max], $oldPages)) { $pages = $oldPages; } else { setCookie("PAGEPATH", $_REQUEST['page'], time() + 86400 * 30, "/"); } } else { setCookie("PAGEPATH", $_REQUEST['page'], time() + 86400 * 30, "/"); } if (count($pages) > 0 && $pages[0] != 'home') { foreach ($pages as $n => $p) { if (strlen($p) <= 0) { continue; } $pth .= "/{$p}"; $t = toTitle(_ling("MENU-" . $p)); if (strtoupper($t) == strtoupper("MENU-" . $p)) { $t = explode("-", $p); if (is_numeric($t[count($t) - 1])) { $t = array_splice($t, 0, count($t) - 1); $t = toTitle(implode("_", $t)); } else { $t = toTitle($p); } } if ($p == $pages[$max]) { echo "<a class='active'>{$t}</a>"; } else { echo "<a href='{$pth}'>{$t}</a>"; } }
public function test_ling() { $actual = _ling('Hello'); $this->assertEquals('Hi', $actual); }
function generateSelectOptions($fieldinfo, $data, $dbKey = "app") { $html = ""; switch ($fieldinfo['type']) { case 'select': if (!isset($fieldinfo['options'])) { $fieldinfo['options'] = []; } foreach ($fieldinfo['options'] as $key => $value) { if (!$value) { continue; } if (is_array($value)) { $cx = []; if (isset($value['label'])) { $vx = $value['label']; unset($value['label']); foreach ($value as $key => $value) { $cx[] = "{$key}='{$value}"; } } else { $vx = ""; } if ($data == $key) { $html .= "<option value='{$key}' " . implode(" ", $cx) . " selected>" . _ling($vx) . "</option>"; } else { $html .= "<option value='{$key}' " . implode(" ", $cx) . ">" . _ling($vx) . "</option>"; } } else { $vx = $value; if ($data == $key) { $html .= "<option value='{$key}' selected>" . _ling($vx) . "</option>"; } else { $html .= "<option value='{$key}'>" . _ling($vx) . "</option>"; } } } break; case 'selectAJAX': $html .= "<option value=''>Loading ...</option>"; break; case 'dataMethod': if (isset($fieldinfo['method'])) { if (is_array($fieldinfo['method']) && isset($fieldinfo['method']['name'])) { if (isset($fieldinfo['method']['params'])) { if (isset($fieldinfo['method']['valuefield'])) { $fieldinfo['method']['params'][$fieldinfo['method']['valuefield']] = $data; } $html .= call_user_func_array($fieldinfo['method']['name'], $fieldinfo['method']['params']); } elseif (isset($fieldinfo['method']['valuefield'])) { $fieldinfo['method']['params'][$fieldinfo['method']['valuefield']] = $data; $html .= call_user_func_array($fieldinfo['method']['name'], $fieldinfo['method']['params']); } else { $html .= call_user_func($fieldinfo['method']['name']); } } else { $html .= call_user_func($fieldinfo['method']); } } break; case 'dataSelector': if (!isset($fieldinfo['orderBy'])) { $fieldinfo['orderBy'] = null; } $noOption = _ling("No Selection"); /*if(!array_key_exists("", $fieldinfo['options']) || $fieldinfo['options']['']===true) { $html.="<option value=''>{$noOption}</option>"; }*/ $html .= createDataSelector($fieldinfo['groupid'], $fieldinfo['orderBy'], $dbKey); break; case 'dataSelectorFromUniques': if (!isset($fieldinfo['col1'])) { if (isset($fieldinfo['columns'])) { $cols = explode(",", $fieldinfo['columns']); $fieldinfo['col1'] = $cols[0]; if (isset($cols[1])) { $fieldinfo['col2'] = $cols[1]; } } } if (!isset($fieldinfo['col2'])) { $fieldinfo['col2'] = $fieldinfo['col1']; } if (!isset($fieldinfo['where'])) { $fieldinfo['where'] = null; } if (!isset($fieldinfo['orderBy'])) { $fieldinfo['orderBy'] = null; } /*if(!array_key_exists("", $fieldinfo['options']) || $fieldinfo['options']['']===true) { $html.="<option value=''>{$noOption}</option>"; }*/ $html .= createDataSelectorFromUniques($fieldinfo['table'], $fieldinfo['col1'], $fieldinfo['col2'], $fieldinfo['where'], $fieldinfo['orderBy'], $dbKey); break; case "dataSelectorFromTable": if (!isset($fieldinfo['columns'])) { $fieldinfo['columns'] = $fieldinfo['col1']; } if (!isset($fieldinfo['where'])) { $fieldinfo['where'] = null; } if (!isset($fieldinfo['groupBy'])) { $fieldinfo['groupBy'] = null; } if (!isset($fieldinfo['orderBy'])) { $fieldinfo['orderBy'] = null; } /*if(!array_key_exists("", $fieldinfo['options']) || $fieldinfo['options']['']===true) { $html.="<option value=''>{$noOption}</option>"; }*/ $html .= createDataSelectorFromTable($fieldinfo['table'], $fieldinfo['columns'], $fieldinfo['where'], $fieldinfo['groupBy'], $fieldinfo['orderBy'], $dbKey); break; } return $html; }
function _msg($msgID) { if (strpos($msgID, "#") === 0) { $msg1 = substr($msgID, 1); $msg2 = _ling($msg1); if ($msg1 == $msg2) { return ""; } else { return $msg2; } } else { return _ling($msgID); } }
function printFormattedArray($arr, $autoTitle = true, $format = null) { if ($format == null) { if (isset($_REQUEST["format"])) { $format = $_REQUEST["format"]; } else { $format = "select"; } } $format = strtolower($format); //HTML Format if ($format == "select") { if (!array_is_associative($arr)) { foreach ($arr as $a => $b) { if ($autoTitle) { echo "<option title='{$b}' value='{$b}'>" . toTitle(_ling($b)) . "</option>\n"; } else { echo "<option title='{$b}' value='{$b}'>" . _ling($b) . "</option>\n"; } } } else { foreach ($arr as $a => $b) { $xs = ""; if (is_array($b)) { $xx = array(); foreach ($b as $x => $y) { $xx[] = "{$x}='{$y}'"; } $xs = implode(" ", $xx); if (isset($b['value'])) { $b = $b['value']; } else { $b = $a; } } if ($autoTitle) { echo "<option title='{$a}' value='{$b}' {$xs}>" . toTitle(_ling($a)) . "</option>\n"; } else { echo "<option title='{$a}' value='{$b}' {$xs}>" . _ling($a) . "</option>\n"; } } } } elseif ($format == "table") { foreach ($arr as $a => $b) { $s = "<tr rel='{$a}'>"; if (is_array($b)) { foreach ($b as $x => $y) { if (is_numeric($y)) { $s .= "<td name='{$x}' rel='{$y}' align=center>" . toTitle(_ling($y)) . "</td>"; } elseif (is_array($y)) { $xs = ""; foreach ($y as $u => $v) { $xx[] = "{$u}='{$v}'"; } $xs = implode(" ", $xx); if (isset($y['value'])) { $y = $y['value']; } else { $y = $x; } $s .= "<td name='{$x}' rel='{$y}' {$xs}>" . toTitle(_ling($y)) . "</td>"; } elseif (is_bool($y) || $y == "true" || $y == "false") { if ($y == "true" || $y == 1) { $s .= "<td name='{$x}' rel='{$y}' align=center><input name={$x} type=checkbox checked /></td>"; } else { $s .= "<td name='{$x}' rel='{$y}' align=center><input name={$x} type=checkbox /></td>"; } } else { if (strpos("#" . $y, "<") == 1) { $s .= "<td name='{$x}' rel='{$x}'>{$y}</td>"; } elseif (strpos($y, "@") === 0) { $y = substr($y, 1); $s .= "<td name='{$x}' rel='{$x}'>{$y}</td>"; } else { $s .= "<td name='{$x}' rel='{$y}'>" . toTitle(_ling($y)) . "</td>"; } } } } else { $s .= "<td name='{$a}' rel='{$b}'>" . toTitle(_ling($b)) . "</td>"; } $s .= "</tr>\n"; echo $s; } } elseif ($format == "list") { if (!array_is_associative($arr)) { foreach ($arr as $a => $b) { if (is_array($b)) { echo "<ul>\n"; printFormattedArray($b, $autoTitle, $format); echo "</ul>\n"; } else { if ($autoTitle) { echo "<li title='{$b}' value='{$b}'>" . toTitle(_ling($b)) . "</li>\n"; } else { echo "<li title='{$b}' value='{$b}'>" . _ling($b) . "</li>\n"; } } } } else { foreach ($arr as $a => $b) { if (is_array($b)) { $xs = ""; if (is_array($b)) { $xx = array(); foreach ($b as $x => $y) { $xx[] = "{$x}='{$y}'"; } $xs = implode(" ", $xx); } if ($autoTitle) { echo "<li title='{$a}' {$xs}>" . toTitle(_ling($a)) . "</li>\n"; } else { echo "<li title='{$a}' {$xs}>" . _ling($a) . "</li>\n"; } // echo "<ul>\n"; // printFormattedArray($b,$autoTitle,$format); // echo "</ul>\n"; } else { if ($autoTitle) { echo "<li title='{$a}' value='{$b}'>" . toTitle(_ling($a)) . "</li>\n"; } else { echo "<li title='{$a}' value='{$b}'>" . _ling($a) . "</li>\n"; } } } } } elseif ($format == "text") { foreach ($arr as $a => $b) { if (is_array($b)) { printFormattedArray($b, $autoTitle, $format); } else { $sx = strip_tags("{$a}={$b}"); echo "{$sx}\n"; } } } elseif ($format == "json") { echo json_encode($arr); } elseif ($format == "xml") { $arr = array_flip($arr); $xml = new SimpleXMLElement('<service/>'); //arrayToXML($arrData,$xml); array_walk_recursive($arr, array($xml, 'addChild')); echo $xml->asXML(); } else { printArray($arr); } }
function createDataSelectorFromSQL($dbLink, $sql, $nameCol, $valCol, $classCol = null, $dataCol = null, $groupCol = null, $concatName = false, $allowNone = true, $format = "select", $params = array()) { if ($valCol == null || strlen($valCol) <= 0) { $valCol = $nameCol; } if ($groupCol != null && strlen($groupCol) > 0) { $groupSelector = true; } else { $groupSelector = false; } //echo $sql; if (isset($params['name'])) { $nameX = $params['name']; } else { $nameX = ""; } $result = $dbLink->executeQuery($sql); if ($allowNone) { if ($format == "select") { $outArr[] = "<option value='' rel=''>" . _ling("None") . "</option>"; } elseif ($format == "checkbox") { $outArr[] = "<input type=checkbox name='{$nameX}' rel='' value='' /> <label for=''>None</label>"; } elseif ($format == "radio") { $outArr[] = "<input type=radio name='{$nameX}' rel='' value='' /> <label for=''>None</label>"; } } else { $outArr = array(); } $lastGroup = ""; $tmpl = ""; if ($format == "select") { $tmpl = "<option class='%s' rel='%s' value='%s' >%s</option>"; } elseif ($format == "checkbox") { $tmpl = "<input type=checkbox name='{$nameX}' class='%s' rel='%s' value='%s' /> <label for=''>%s</label>"; } elseif ($format == "radio") { $tmpl = "<input type=radio name='{$nameX}' class='%s' rel='%s' value='%s' /> <label for=''>%s</label>"; } if ($result) { if ($dbLink->recordCount($result) > 0) { while ($record = $dbLink->fetchData($result)) { if ($record[$valCol] == null) { $record[$valCol] = $record[$nameCol]; } $name = $record[$nameCol]; $name = str_replace('_', ' ', $name); $name = ucwords($name); $name = _ling($name); if ($concatName) { $name = $name . " [" . $record[$valCol] . "]"; } if ($classCol != null && strlen($classCol) > 0 && isset($record[$classCol])) { $c = $record[$classCol]; } else { $c = ""; } if ($dataCol != null && strlen($dataCol) > 0 && isset($record[$dataCol])) { $d = $record[$dataCol]; } else { $d = ""; } if (isset($params['class'])) { $c = $params['class']; } if (isset($params['rel'])) { $d = $params['rel']; } $str = sprintf($tmpl, $c, $d, $record[$valCol], _ling($name)); if ($groupSelector) { if (isset($record[$groupCol]) && strlen($record[$groupCol]) > 0) { if (!isset($outArr[$record[$groupCol]])) { $outArr[$record[$groupCol]] = array(); } array_push($outArr[$record[$groupCol]], $str); } else { $outArr[] = $str; } } else { $outArr[] = $str; } } } } $str = ""; foreach ($outArr as $a => $b) { if (is_array($b)) { if ($format == "select") { $str .= "<optgroup label='" . toTitle($a) . "' value='{$a}'>"; foreach ($b as $x) { $str .= $x; } $str .= "</optgroup>"; } else { $str .= "<span label='" . toTitle($a) . "' value='{$a}'>"; foreach ($b as $x) { $str .= $x; } $str .= "</span>"; } } else { $str .= $b; } } $dbLink->freeResult($result); return $str; }
function byte_format($num, $precision = 1) { if ($num >= 1000000000000) { $num = round($num / 1099511627776, $precision); $unit = _ling('TB'); } elseif ($num >= 1000000000) { $num = round($num / 1073741824, $precision); $unit = _ling('GB'); } elseif ($num >= 1000000) { $num = round($num / 1048576, $precision); $unit = _ling('MB'); } elseif ($num >= 1000) { $num = round($num / 1024, $precision); $unit = _ling('KB'); } else { $unit = _ling('Bytes'); return number_format($num) . ' ' . $unit; } return number_format($num, $precision) . ' ' . $unit; }