PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/application/helpers/zetro_helper.php

https://gitlab.com/zetrosoft/pos-ci
PHP | 367 lines | 342 code | 17 blank | 8 comment | 33 complexity | 59cfc168a6afe9e13577d0f1bf987c55 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. function __construct(){
  3. }
  4. function check_logged_in($status=FALSE){
  5. if ( $status!= TRUE) {
  6. redirect('admin/index', 'refresh');
  7. exit();
  8. }
  9. }
  10. function hapus_table($table,$where){
  11. $sql="delete from $table $where";
  12. mysql_query($sql) or die(mysql_error());
  13. }
  14. function rdb($tabel,$rfield,$sfield='',$where='',$order='',$group=''){
  15. $datadb="";
  16. if($sfield==''){
  17. $sql="select * from ".$tabel." $where $group $order";
  18. }else{
  19. $sql="select ".$sfield." from ".$tabel." $where $group $order";
  20. }
  21. //echo $sql."\n"; //for debug only;
  22. $rs=mysql_query($sql) or die($sql.mysql_error());
  23. while($rw=mysql_fetch_array($rs)){
  24. $datadb=$rw[$rfield];
  25. }
  26. return $datadb;
  27. }
  28. function RowCount($tabel,$where='',$sfield='*'){
  29. $databd=0;
  30. $sql="select $sfield from $tabel $where";
  31. $rs=mysql_query($sql) or die($sql.mysql_error());
  32. $datadb=mysql_num_rows($rs);
  33. return $datadb;
  34. }
  35. function hapus($tabel,$where){
  36. $sql="delete from $tabel $where";
  37. mysql_query($sql) or die(mysql_error());
  38. }
  39. function dropdown($tabel,$fieldforval,$fieldforname='',$where='',$pilih='',$bariskosong=true,$sparator=' - '){
  40. if ($bariskosong==true) echo "<option value=''>&nbsp;</option>";
  41. $dst=explode(" as ",$fieldforval);
  42. if($fieldforname!=''){$dst2=explode("+",$fieldforname);}
  43. ($fieldforname=='')?
  44. $sql="select $fieldforval from $tabel $where":
  45. (count($dst2)>1)?
  46. $sql="select * from $tabel $where":
  47. $sql="select $fieldforval,$fieldforname from $tabel $where";
  48. //echo $sql;
  49. $rs=mysql_query($sql) or die(mysql_error());
  50. while ($rw=mysql_fetch_object($rs)){
  51. (count($dst)>1)? $valu=$rw->$dst[1]: $valu=$rw->$dst[0];
  52. ($sparator==' [')? $sp_end=' ]':$sp_end='';
  53. if($fieldforname!='')(count($dst2)>1)? $addnm=$rw->$dst2[0].$sparator.$rw->$dst2[1].$sp_end :$addnm=$rw->$dst2[0];
  54. echo "<option value='".$valu."'";if ($pilih==$valu){ echo " selected";}
  55. echo " >";echo ($fieldforname=='')? $rw->$dst[1]:$addnm."</option>";
  56. }
  57. }
  58. function selectTxt($section,$bariskosong=false,$path='asset/bin/zetro_beli.frm'){
  59. $zn= new zetro_manager();$data='';
  60. $countX=$zn->Count($section,$path);
  61. $data=($bariskosong==true)?"<option value=''>&nbsp;</option>":'';
  62. for ($i=1;$i<=$countX;$i++){
  63. $content=explode(',',$zn->rContent($section,$i,$path));
  64. $data=$data."<option value='".$content[0]."'>".$content[1]."</option>";
  65. }
  66. return $data;
  67. }
  68. function lama_execute(){
  69. $awal = microtime(true);
  70. // --- bagian yang akan dihitung execution time --
  71. $bil = 2;
  72. $hasil = 1;
  73. for ($i=1; $i<=10000000; $i++)
  74. {
  75. $hasil .= $bil;
  76. }
  77. // --- bagian yang akan dihitung execution time --
  78. $akhir = microtime(true);
  79. $lama = $akhir - $awal;
  80. return $lama;
  81. }
  82. function nBulan($bln){
  83. $bulan=array('','Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September',
  84. 'Oktober','November','Desember');
  85. return $bulan[(int)$bln];
  86. }
  87. function penomoran($table,$fieldnomor){
  88. $nom=rdb($table,$fieldnomor,$fieldnomor,"order by $fieldnomor desc limit 1");
  89. if ($nom==""){
  90. $nomor=date('Ymd')."-0001";
  91. }else{
  92. $noms=explode("-",$nom);
  93. if (strlen((int)$noms[1])==1){
  94. $nomor=date('Ymd')."-000".($noms[1]+1);
  95. }else if(strlen((int)$noms[1])==2){
  96. $nomor=date('Ymd')."-00".($noms[1]+1);
  97. }else if(strlen((int)$noms[1])==3){
  98. $nomor=date('Ymd')."-0".($noms[1]+1);
  99. }else if(strlen((int)$noms[1])==4){
  100. $nomor=date('Ymd')."-".($noms[1]+1);
  101. }
  102. }
  103. return $nomor;
  104. }
  105. function tglToSql($tgl=''){
  106. //input dd/mm/yyyy -->output yyyymmdd
  107. if($tgl==''){
  108. $tanggal=date('Ymd');
  109. }else{
  110. $tanggal=substr($tgl,6,4).substr($tgl,3,2).substr($tgl,0,2);
  111. }
  112. return $tanggal;
  113. }
  114. function tglfromSql($tgl='',$separator='/'){
  115. ($tgl=='')?
  116. $tanggal='':
  117. $tanggal=substr($tgl,8,2).$separator.substr($tgl,5,2).$separator.substr($tgl,0,4);
  118. return $tanggal;
  119. }
  120. function ShortTgl($tgl='',$withYear=false){
  121. ($tgl=='')?
  122. $tanggal=date('d/m'):
  123. $tanggal=($withYear==true)?substr($tgl,8,2).'/'.substr($tgl,5,2).'/'.substr($tgl,2,2):substr($tgl,8,2).'/'.substr($tgl,5,2);
  124. return $tanggal;
  125. }
  126. function LongTgl($tgl=''){
  127. ($tgl=='')? $tanggal=date('d F Y'):
  128. $tanggal=substr($tgl,0,2)." ". nBulan(round(substr($tgl,3,2),0))." ". substr($tgl,6,4);
  129. return $tanggal;
  130. }
  131. function no_auth(){
  132. echo "<img src='".base_url()."asset/images/warning.png'>";?>
  133. <font style="font-family:'20th Century Font', Arial; color:#DD0000; font-size:x-large">
  134. <? $zn= new zetro_manager();
  135. echo $zn->rContent("Message","NoAuth","asset/bin/form.cfg");
  136. ?>
  137. </font>
  138. <?
  139. }
  140. function panel_begin($section,$form='',$filter='',$printer='',$file='asset/bin/zetro_menu.dll'){
  141. //$judul= explode(',',$judul);]
  142. $data=array();
  143. $zn=new zetro_manager();
  144. //echo "<div class='pn_contents t'>\n";
  145. $jml=$zn->Count($section,$file);
  146. for($i=1;$i<=$jml;$i++){
  147. $mnu=explode('|',$zn->rContent($section,$i,$file));
  148. if(strtolower($mnu[2]=='y')) $data[]=$mnu[0];
  149. }
  150. echo str_repeat("<br>",3);
  151. echo"<table width='100%' style='border-collapse:collapse' border='0' bordercolor='#CCC' id='panel'>\n
  152. <tr height='40px' align='center' valign='middle'>\n";
  153. foreach ($data as $menu){
  154. echo "<td nowrap='nowrap' class='tab_button tab_font' id='".strtolower(str_replace(" ",'',$menu))."'>".strtoupper($menu)."</td>\n";
  155. }
  156. if($filter!=''){
  157. echo "<td width='10px' class='flt'>&nbsp;</td>\n";
  158. $flt=explode(',',$filter);
  159. for($z=0;$z< count($flt);$z++){
  160. echo "<td align='left' bgcolor='' id='' width='100px' nowrap class='flt'>".$flt[$z]."</td>\n";
  161. }
  162. }
  163. if($printer!=''){
  164. ($filter=='')?$wd='200px':$wd='50px';
  165. echo "<td style='width:$wd' class='plt'>&nbsp;</td>\n";
  166. $flt=explode(',',$printer);
  167. for($z=0;$z< count($flt);$z++){
  168. echo "<td bgcolor='' id='p-$z' style='padding-right:27px' width='50px' class='plt' align='right' nowrap >";
  169. echo $flt[$z].'&nbsp;';
  170. echo "</td>\n";
  171. }
  172. }
  173. echo "<td class='tab_kosong' id='kosong'>&nbsp;</td></tr></table>\n
  174. <div class='content tab_content' style='height:81%'>\n";
  175. echo ($form!='')? "<form id='$form' name='$form' action='' method='post'>\n":'';
  176. }
  177. function panel_multi($id,$display='none',$br=true){
  178. echo ($br==true)?"<br>":"";
  179. echo "<span id='v_$id' style='display:$display;padding:5px'>\n";
  180. }
  181. function panel_multi_end($br=true){
  182. //echo ($br==true)? "</div>":"";
  183. echo "</span>\n";
  184. }
  185. function panel_end($form=false){
  186. echo "</div>\n";
  187. echo ($form==true)? "</form>\n":'';
  188. }
  189. function link_js($js,$path){
  190. $js=explode(",",$js);$pathe=explode(",",$path);
  191. for ($i=0;$i< count($js);$i++){
  192. echo "<script language='javascript' src='".base_url().$pathe[$i]."/".$js[$i]."' type='text/javascript'></script>\n";
  193. }
  194. }
  195. function link_css($css,$path){
  196. $css=explode(",",$css);$pathe=explode(",",$path);
  197. for ($i=0;$i< count($css);$i++){
  198. echo "<link href='".base_url().$pathe[$i]."/".$css[$i]."' type='text/css' rel='stylesheet'>\n";
  199. }
  200. }
  201. function popup_start($name,$caption='',$width='500',$height='500'){
  202. ?> <div id='lock<?=$name;?>' class='black_overlay'></div>
  203. <div id='lock' class='black_overlay'></div>
  204. <div id='pp-<?=$name;?>' align="center" style='display:none; background:#CCC; border:5px solid #000; padding:0px; left:0; top:0; width:<?=$width;?>px; max-height:<?=$height;?>px; position:fixed; overflow:auto; z-index:9999'>
  205. <table id='lvltbl0' width="100%" style='border-collapse:collapse;'>
  206. <tr><td bgcolor="#000" width='3%' ><img src='<?=base_url();?>asset/images/16/address_16.png' /></td>
  207. <td colspan='' bgcolor="#000" class=''>
  208. <font style='font-size:14px; font-weight:bold; color:#FFFFFF'><?=$caption;?></font></td>
  209. <td bgcolor="#000" align="center" width="10px"><font color="#FFFFFF">
  210. <img src="<?=base_url();?>asset/images/no.png" id='<?=$name;?>' onclick="keluar_<?=$name;?>();" class='close' style='cursor:pointer' title="Close"/></font></td></tr>
  211. <input type='hidden' value='<?=$name;?>' id='nama' />
  212. </table>
  213. <script language='javascript'>
  214. function keluar_<?=$name;?>(){
  215. $('#pp-<?=$name;?>').hide('slow');
  216. $('#lock').hide();
  217. $('#lock<?=$name;?>').hide();
  218. }
  219. </script>
  220. <div id='tbl-<?=$name;?>' style='padding:3px; width:95%' align="left">
  221. <?
  222. }
  223. function popup_end(){
  224. echo "</div></div>\n";
  225. }
  226. function getNextDays($fromdate,$countdays) {
  227. $dated='';
  228. $time = strtotime($fromdate); // 20091030
  229. $day = 60*60*24;
  230. for($i = 0; $i<$countdays; $i++)
  231. {
  232. $the_time = $time+($day*$i);
  233. $dated = date('Y-m-d',$the_time);
  234. }
  235. return $dated;
  236. }
  237. function getPrevDays($fromdate,$countdays) {
  238. $dated='';
  239. $time = strtotime($fromdate); // 20091030
  240. $day = 60*60*24;
  241. for($i = 0; $i <$countdays; $i++)
  242. {
  243. $the_time = $time-($day*$i);
  244. $dated = date('Ymd',$the_time);
  245. }
  246. return $dated;
  247. }
  248. function compare_date($date_1,$date_2){
  249. list($year, $month, $day) = explode('-', $date_1);
  250. $new_date_1 = sprintf('%04d%02d%02d', $year, $month, $day);
  251. list($year, $month, $day) = explode('-', $date_2);
  252. $new_date_2 = sprintf('%04d%02d%02d', $year, $month, $day);
  253. ($new_date_1 <= $new_date_2)? $data=true:$data=false;
  254. return $data;
  255. }
  256. function auto_sugest(){
  257. echo "<div class='autosuggest' id='autosuggest_list'></div>";
  258. }
  259. function tab_select($select){
  260. echo "<input type='hidden' value='$select' id='prs'>";
  261. }
  262. function inline_edit($frm=''){
  263. echo "<span id='ild' style='display:none'>
  264. <input type='text' id='inedit_$frm' value='' style='width:70%; height:20px' class='angka'>
  265. <img src='".base_url()."asset/images/Save.png' id='saved-$frm' onclick=\"simpan_$frm('inedit-$frm');\" class='simpan'>
  266. <img src='".base_url()."asset/images/no.png' id='gakjadi' onclick=\"batal_$frm();\" class='hapus'>
  267. </span>";
  268. }
  269. function tab_head($section='Menu Utama',$bg='',$file='asset/bin/zetro_menu.dll'){
  270. $data=array();
  271. $zn=new zetro_manager();
  272. $jml=$zn->Count($section,$file);
  273. for($i=1;$i<=$jml;$i++){
  274. $mnu=explode("|",$zn->rContent($section,$i,$file));
  275. if(strtolower($mnu[2])=='y')$data[]=$mnu[0];
  276. }
  277. echo"<table width='100%' style='border-collapse:collapse' border='0' bordercolor='#CCC' id='tab'>\n
  278. <tr height='35px' align='center'>\n";
  279. foreach($data as $menu){
  280. echo "<td width='100px' style='padding:5px' class='tab_button' id='".strtolower(str_replace(" ",'',$menu))."'>".$menu."</td>\n";
  281. }
  282. echo "<td class='tab_kosong' id='kosong' $bg>&nbsp;</td></tr></table>
  283. <div id='v_panel' class='pn_contents tab_content' style='height:75%; overflow:auto'>
  284. ";
  285. }
  286. function tab_head_end(){
  287. echo "</div>";
  288. }
  289. function terbilang(){
  290. echo "<div id='terbilang' class='infox'></div>";
  291. }
  292. function loading_ajax(){
  293. echo "<div id='ajax_start' style='display:none; position:fixed; left:45%; top:50%; z-index:9999' align='center'>
  294. <img src='".base_url()."asset/images/ajax-loader.gif' /></div>
  295. <div id='lock' class='black_overlay'></div>";
  296. }
  297. function addText($label,$field,$hr=true,$frm=''){
  298. echo ($hr==true)?"":"<hr>\n";
  299. echo ($frm=='')?'':"<form id='$frm' name='$frm' method='post' action=''>\n";
  300. echo "<table style='border-collapse:collapse' id='addtxt'><tr>\n";
  301. $n=0;
  302. foreach($label as $lbl){
  303. ($lbl=='')?$width="5":$width=(strlen($lbl)*5+20);
  304. echo "<td id='c1-$n' width='".$width."px' align='' valign='middle' nowrap>".$lbl."</td>
  305. <td id='c2-$n'>".$field[$n]."</td>\n";
  306. echo (count($label)>1 && ($n+1)<count($label))?"<td width='10px' align='center' style='background: url(".base_url()."asset/images/on_bg.png) repeat-y center' >&nbsp;</td>\n":"";
  307. $n++;
  308. }
  309. echo "</tr>\n</table>";
  310. echo ($frm=='')?'':"</form>\n";
  311. echo ($hr==true)?"<hr>\n":"";
  312. }
  313. function popup_full($include=''){
  314. echo "<div id='mm_lock' class='black_overlay'></div>";
  315. echo "<div id='mm_detail'></div>";
  316. }
  317. function calender(){
  318. link_css('calendar-win2k-cold-1.css','asset/calender/css');
  319. link_js('jquery.dynDateTime.js,calendar-en.js','asset/calender,asset/calender/lang');
  320. }
  321. function createDir($name="c:/app"){
  322. $a=is_dir($name);
  323. (!$a)? mkdir($name,0777):'';
  324. system("attrib +H $name");
  325. }
  326. function addCopy(){
  327. createDir();
  328. $find=fopen("c:\\app\\wincopy.dll","a+");
  329. $data= fread($find,1024);
  330. fclose($find);
  331. return $data;
  332. }
  333. function img_aksi($id='',$del=false,$only=''){
  334. $data='';
  335. if($del==false){
  336. $data="<img src='".base_url()."asset/images/editor.png' id='simpan' onclick=\"images_click('".$id."','edit');\" class='simpan' title='Click to Edit'>";
  337. }else if ($del==true && $only=='del'){
  338. $data="<img src='".base_url()."asset/images/no.png' id='simpan' onclick=\"images_click('".$id."','del');\" class='simpan' title='Click to delete'>";
  339. }else if($del==true && $only==''){
  340. $data="<img src='".base_url()."asset/images/editor.png' id='simpan' onclick=\"images_click('".$id."','edit');\" class='simpan' title='Click to Edit '>
  341. &nbsp;<img src='".base_url()."asset/images/no.png' id='hapus' onclick=\"images_click('".$id."','del');\" class='hapus' title='Click to Delete'>";
  342. }
  343. return $data;
  344. }
  345. function capital($text,$besar=false){
  346. ($besar==false)?
  347. ucwords(strtolower($text)):
  348. strtoupper($text);
  349. }
  350. ?>