EPESI BIM • Business Information Manager • Cloud CRM/ERP http://epe.si/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

285 lines
7.1 KiB

  1. <?php
  2. /**
  3. * @author Paul Bukowski <pbukowski@telaxus.com>
  4. * @copyright Copyright &copy; 2006, Telaxus LLC
  5. * @license MIT
  6. * @version 1.0
  7. * @package epesi-base
  8. */
  9. //TODO: menu tree
  10. define('MOBILE_DEVICE',1);
  11. define('CID',false);
  12. require_once('include.php');
  13. ModuleManager::load_modules();
  14. class LinkEntry {
  15. public $func = null;
  16. public $args = array();
  17. public $caption = null;
  18. public function __construct($f,$a=array(),$c) {
  19. $this->caption = $c;
  20. $this->func = $f;
  21. $this->args = $a;
  22. }
  23. }
  24. class StackEntry {
  25. public $caption = null;
  26. public $func = null;
  27. public $args = array();
  28. public $links = array();
  29. public function __construct($c,$f=null,$a=array()) {
  30. if($c instanceof LinkEntry) {
  31. $this->caption = $c->caption;
  32. $this->func = $c->func;
  33. $this->args = $c->args;
  34. } else {
  35. if($f===null)
  36. trigger_error('Invalid StackEntry usage');
  37. $this->caption = $c;
  38. $this->func = $f;
  39. $this->args = $a;
  40. }
  41. }
  42. public function go() {
  43. return call_user_func_array(str_replace('"','',$this->func),$this->args);
  44. }
  45. }
  46. function mobile_stack_href($func,$args = array(),$caption=null) {
  47. $s = new LinkEntry($func,$args,$caption);
  48. $md5 = md5(serialize($s));
  49. end($_SESSION['stack'])->links[$md5]=$s;
  50. return 'href="mobile.php?'.http_build_query(array('page'=>$md5)).'"';
  51. }
  52. function sort_menus_cmp($a, $b) {
  53. global $menus_out_tmp;
  54. $aw = isset($menus_out_tmp[$a][2]) ? $menus_out_tmp[$a][2]:0;
  55. $bw = isset($menus_out_tmp[$b][2]) ? $menus_out_tmp[$b][2]:0;
  56. if(!isset($aw) || !is_numeric($aw)) $aw=0;
  57. if(!isset($bw) || !is_numeric($bw)) $bw=0;
  58. if($aw==$bw)
  59. return strcasecmp($a, $b);
  60. return $aw-$bw;
  61. }
  62. function mobile_menu() {
  63. $menus = ModuleManager::call_common_methods('mobile_menu');
  64. global $menus_out, $menus_out_tmp;
  65. $menus_out = array();
  66. foreach($menus as $m=>$r) {
  67. if(!is_array($r)) continue;
  68. foreach($r as $cap=>$met) {
  69. if(is_array($met)) {
  70. if(!isset($met['func'])) continue;
  71. $method = array($m.'Common',$met['func']);
  72. $args = isset($met['args'])?$met['args']:array();
  73. $weight = isset($met['weight'])?$met['weight']:0;
  74. $color = isset($met['color'])?$met['color']:'white';
  75. } else {
  76. $method = array($m.'Common',$met);
  77. $args = array();
  78. $weight = 0;
  79. $color='white';
  80. }
  81. $menus_out[$cap] = array($method,$args,$weight,$color);
  82. }
  83. }
  84. $menus_out_tmp = $menus_out;
  85. uksort($menus_out,'sort_menus_cmp');
  86. foreach($menus_out as $cap=>$met) {
  87. print('<a '.mobile_stack_href($met[0],$met[1],$cap).' '.(IPHONE?' class="button '.$met[3].'"':'').'>'.$cap.'</a>'.(IPHONE?'':'<br>'));
  88. }
  89. }
  90. if(!isset($_SESSION['stack']))
  91. $_SESSION['stack'] = array();
  92. $stack = & $_SESSION['stack'];
  93. //if emtpy push menu
  94. if(empty($stack)) {
  95. $m = new StackEntry('Menu','mobile_menu');
  96. $stack[] = $m;
  97. }
  98. //back action
  99. if(isset($_GET['back'])) {
  100. $stack = array_slice($stack,0,(int)$_GET['back']);
  101. header('Location: mobile.php');
  102. exit();
  103. }
  104. //go action
  105. $page = end($stack);
  106. if(isset($_GET['page'])) {
  107. $l = & $page->links;
  108. if(isset($l[$_GET['page']])) {
  109. $page = new StackEntry($l[$_GET['page']]);
  110. $stack[] = $page;
  111. header('Location: mobile.php');
  112. exit();
  113. }
  114. }
  115. $csses = array();
  116. $page->links = array(); //clear page links
  117. ob_start();
  118. $ret = $page->go();
  119. $body = ob_get_clean();
  120. $captions = array();
  121. foreach($stack as $s)
  122. if($s->caption)
  123. $captions[] = $s->caption;
  124. $back_id = 0;
  125. if(IPHONE) {
  126. $title = end($captions);
  127. $back_id = key($captions);
  128. array_pop($captions);
  129. $back = '';
  130. $is_back = end($captions);
  131. if(end($stack)->caption!==$title) {
  132. if($is_back) {
  133. $back = '<a href="mobile.php?back='.($back_id+1).'" class="nav" id="backButton">'.$title.'</a>';
  134. $back_id = key($captions);
  135. $action = '<a href="mobile.php?back='.($back_id+1).'" class="nav Action">'.$is_back.'</a>';
  136. } else {
  137. $back = '<a href="mobile.php?back='.($back_id+1).'" class="nav Action">'.$title.'</a>';
  138. $action = '';
  139. }
  140. } else {
  141. $action = '';
  142. if($is_back) {
  143. $back_id = key($captions);
  144. $back = '<a href="mobile.php?back='.($back_id+1).'" class="nav" id="backButton">'.$is_back.'</a>';
  145. }
  146. }
  147. $title = '<h1>'.$title.'</h1>';
  148. $caption = $back.$title.$action;
  149. } else {
  150. $cap = array();
  151. $last_back_id = 0;
  152. foreach($captions as $k=>$c) {
  153. $cap[] = '<a href="mobile.php?back='.($k+1).'">'.$c.'</a>';
  154. $last_back_id = $back_id;
  155. $back_id = $k;
  156. }
  157. $back_id = $last_back_id;
  158. // array_pop($cap); //don't display current breadthumb
  159. $caption = implode($cap,' > ');
  160. }
  161. if(isset($ret) && ($ret===false || is_numeric($ret))) {
  162. if(is_numeric($ret))
  163. $b = $back_id+2-$ret;
  164. else
  165. $b = $back_id+1;
  166. $stack = array_slice($stack,0,$b);
  167. header('Location: mobile.php');
  168. exit();
  169. }
  170. $csses = Epesi::get_csses();
  171. if(IPHONE) {
  172. ?>
  173. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  174. <html xmlns="http://www.w3.org/1999/xhtml">
  175. <head>
  176. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  177. <meta id="viewport" name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
  178. <title>epesi CRM</title>
  179. <link rel="stylesheet" href="libs/UiUIKit/stylesheets/iphone.css" />
  180. <link rel="apple-touch-icon" href="images/apple-favicon.png" />
  181. <script type="text/javascript" charset="utf-8">
  182. function clickclear(thisfield, defaulttext) {
  183. if (thisfield.value == defaulttext) {
  184. thisfield.value = "";
  185. }
  186. }
  187. function clickrecall(thisfield, defaulttext) {
  188. if (thisfield.value == "") {
  189. thisfield.value = defaulttext;
  190. }
  191. }
  192. window.onload = function() {
  193. setTimeout(function(){window.scrollTo(0, 1);}, 100);
  194. }
  195. </script>
  196. <?php
  197. foreach($csses as $f)
  198. print('<link href="'.$f.'" type="text/css" rel="stylesheet"/>'."\n");
  199. ?>
  200. </head>
  201. <body id="normal">
  202. <div id="header">
  203. <?php print($caption); ?>
  204. </div>
  205. <?php print($body); ?>
  206. </body>
  207. </html>
  208. <?php
  209. } else {
  210. ?>
  211. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  212. <html>
  213. <head>
  214. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  215. <title>Epesi</title>
  216. <link href="mobile.css" type="text/css" rel="stylesheet"/>
  217. <?php
  218. foreach($csses as $f)
  219. print('<link href="'.$f.'" type="text/css" rel="stylesheet"/>'."\n");
  220. ?>
  221. <script type="text/javascript" charset="utf-8">
  222. function clickclear(thisfield, defaulttext) {
  223. if (thisfield.value == defaulttext) {
  224. thisfield.value = "";
  225. }
  226. }
  227. function clickrecall(thisfield, defaulttext) {
  228. if (thisfield.value == "") {
  229. thisfield.value = defaulttext;
  230. }
  231. }
  232. </script>
  233. </head>
  234. <body>
  235. <table id="banner" border="0" cellpadding="0" cellspacing="0">
  236. <tr>
  237. <td class="back"><?php print($caption); ?></td>
  238. </tr>
  239. </table>
  240. <br>
  241. <center>
  242. <table id="main" border="0" cellpadding="0" cellspacing="0">
  243. <tr>
  244. <td>
  245. <?php print($body); ?>
  246. </td>
  247. </tr>
  248. </table>
  249. </center>
  250. <br>
  251. <center>
  252. <span class="footer">Copyright &copy; <?php print(date('Y')); ?> &bull; <a href="http://www.telaxus.com">Telaxus LLC</a></span>
  253. <br>
  254. <p><a href="http://www.epesi.org"><img src="images/epesi-powered.png" border="0"></a></p>
  255. </center>
  256. </body>
  257. </html>
  258. <?php
  259. }
  260. ?>