init.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. //error_reporting(E_ALL^E_NOTICE);
  3. ini_set("register_globals", "On");
  4. #if (eregi('http', $_SERVER["SERVER_PROTOCOL"])) ob_start('ob_gzhandler');
  5. require_once dirname(__FILE__).'/config.php';
  6. require_once dirname(__FILE__).'/adodb/adodb.inc.php';
  7. $ADODB_SESSION_DRIVER = $adodb_scheme;
  8. $ADODB_SESSION_CONNECT = $adodb_host;
  9. $ADODB_SESSION_USER = $adodb_user;
  10. $ADODB_SESSION_PWD = $adodb_pass;
  11. $ADODB_SESSION_DB = $adodb_db;
  12. $ADODB_SESSION_TBL = 'qb_sessions';
  13. $ADODB_SESSION_EXPIRE_NOTIFY = array('userid','NotifyFn');
  14. function NotifyFn($expireref, $sesskey) {
  15. global $ADODB_SESS_CONN; # the session connection object
  16. $user = $ADODB_SESS_CONN->qstr($expireref);
  17. $ADODB_SESS_CONN->Execute("UPDATE qb_changelog ".
  18. " SET newval = NULL WHERE newval = ?", array($sesskey));
  19. }
  20. require_once dirname(__FILE__).'/adodb/session/adodb-session.php';
  21. @session_start();
  22. $adodb = NewADOConnection($adodb_dsn);
  23. if (!$adodb) die($adodb->ErrorMsg());
  24. $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
  25. if (! function_exists('removeSlashes')) {
  26. function removeSlashes(&$a){
  27. if(count($a)>0) {
  28. foreach($a as $i=>$v) {
  29. if(is_array($a[$i])) {
  30. removeSlashes($a[$i]);
  31. } else {
  32. $a[$i]=stripslashes($v);
  33. }
  34. }
  35. }
  36. }
  37. }
  38. if (get_magic_quotes_gpc()) {
  39. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  40. removeSlashes($_POST);
  41. } else if ($_SERVER['REQUEST_METHOD'] == "GET") {
  42. removeSlashes($_GET);
  43. }
  44. }
  45. /* not use anymore
  46. if (! function_exists('htmlTitle')) {
  47. function htmlTitle($title) {
  48. echo "
  49. <div class=titlebox>
  50. <div class=h1>
  51. $title
  52. </div>
  53. </div>";
  54. }
  55. }
  56. */
  57. if (! function_exists('getUserMenu')) {
  58. function getUserMenu($userId) {
  59. global $adodb, $CACHE_userMenu;
  60. if (isset($CACHE_userMenu)) return $CACHE_userMenu;
  61. $rs = $adodb->Execute("SELECT menu FROM qb_user_right ".
  62. " WHERE userid = '".$userId."'");
  63. $userMenu = $rs->fields['menu'];
  64. $rs = $adodb->Execute("SELECT userid, group_name FROM qb_user_group ".
  65. " WHERE userid LIKE '%".$userId."%'");
  66. while (!$rs->EOF && !$groupName) {
  67. $listUser = $rs->fields['userid'];
  68. $pieUser = explode(",", $listUser);
  69. foreach ($pieUser as $k => $v) {
  70. if ($v === $userId) {
  71. $groupName = $rs->fields['group_name'];
  72. break;
  73. }
  74. }
  75. $rs->MoveNext();
  76. }
  77. $rs = $adodb->Execute("SELECT menu FROM qb_group_right ".
  78. " WHERE group_name = '".$groupName."'");
  79. $groupMenu = $rs->fields['menu'];
  80. if ($userMenu) $userMenu .= ",";
  81. if ($groupMenu) $userMenu .= $groupMenu;
  82. $CACHE_userMenu = $userMenu;
  83. return $CACHE_userMenu;
  84. }
  85. }
  86. if (! function_exists('getUserActions')) {
  87. function getUserActions($userId, $moduleId) {
  88. global $adodb,$CACHE_arrAction;
  89. if (isset($CACHE_arrAction)) return $CACHE_arrAction;
  90. $userMenu = getUserMenu($userId);
  91. $where = str_replace(",", "','", $userMenu);
  92. $rs = $adodb->Execute("SELECT action FROM qb_right ".
  93. " WHERE id IN ('".$where."') AND module = '".$moduleId."'");
  94. $arrAction = array();
  95. while (!$rs->EOF) {
  96. $action = $rs->fields['action'];
  97. $p = explode(",", $action);
  98. foreach ($p as $k => $v) {
  99. $arrAction[$v] = 1;
  100. }
  101. $rs->MoveNext();
  102. }
  103. $CACHE_arrAction = $arrAction;
  104. return $CACHE_arrAction;
  105. }
  106. }
  107. if (! function_exists('getReportActions')) {
  108. function getReportActions($userId, $moduleId) {
  109. global $adodb,$CACHE_arrReport;
  110. if (isset($CACHE_arrReport)) return $CACHE_arrReport;
  111. $rs = $adodb->Execute("SELECT action FROM qb_user_report ".
  112. " WHERE userid = ? AND name = ?", array($userId, $moduleId));
  113. $arrReport = array();
  114. while (!$rs->EOF) {
  115. $action = $rs->fields['action'];
  116. $p = explode(",", $action);
  117. foreach ($p as $k => $v) {
  118. $arrReport[$v] = 1;
  119. }
  120. $rs->MoveNext();
  121. }
  122. $CACHE_arrReport = $arrReport;
  123. return $CACHE_arrReport;
  124. }
  125. }
  126. if (! function_exists('getUserOpts')) {
  127. function getUserOpts($userId, $moduleId, $arrDefaults=array()) {
  128. global $adodb, $arrOptions, $CACHE_opts;
  129. if (isset($CACHE_opts)) return $CACHE_opts;
  130. $arrAction = getUserActions($userId, $moduleId);
  131. $opts['filters'] = '1=0';
  132. $opts['options'] = '';
  133. foreach ($arrAction as $k => $v) {
  134. if ($k === 'list') $opts['filters'] = '';
  135. else {
  136. if (isset($arrDefaults[$arrOptions[$k]])) {
  137. $opts['options'] .= $arrOptions[$k];
  138. }
  139. }
  140. }
  141. $CACHE_opts = $opts;
  142. return $CACHE_opts;
  143. }
  144. }
  145. if (! function_exists('getUserOptions')) {
  146. function getUserOptions($moduleId, $strDefaults='') {
  147. global $isSupervisor;
  148. $userId = $_SESSION['userid'];
  149. if ($isSupervisor) return $strDefaults;
  150. $arrDefaults = array();
  151. for ($i=0,$j=strlen($strDefaults);$i<$j;$i++) {
  152. $arrDefaults[$strDefaults[$i]] = 1;
  153. }
  154. global $adodb;
  155. $opts = getUserOpts($userId, $moduleId, $arrDefaults);
  156. return $opts['options'];
  157. }
  158. }
  159. if (! function_exists('getUserFilters')) {
  160. function getUserFilters($moduleId, $strDefaults='') {
  161. global $isSupervisor;
  162. $userId = $_SESSION['userid'];
  163. if ($isSupervisor) return $strDefaults;
  164. global $adodb;
  165. $opts = getUserOpts($userId, $moduleId);
  166. if ($strDefaults && $opts['filters']) $strDefaults .= " AND ";
  167. return $strDefaults.$opts['filters'];
  168. }
  169. }
  170. if (! function_exists('__')) {
  171. function __($str, $default=null, $module="GENERAL") {
  172. global $arrDictionary, $arrFILE;
  173. $oldstr = $str;
  174. if (!isset($arrDictionary)) {
  175. loadDictionary();
  176. }
  177. if (isset($arrFILE[basename($module)])) {
  178. $module = $arrFILE[basename($module)];
  179. }
  180. $module = strtolower($module);
  181. $str = strtolower($str);
  182. if (isset($arrDictionary[$module][$str])) {
  183. return $arrDictionary[$module][$str];
  184. }
  185. if ($default !== null) return $default;
  186. return $oldstr;
  187. }
  188. }
  189. if (! function_exists('loadDictionary')) {
  190. function loadDictionary() {
  191. global $adodb, $arrDictionary;
  192. $userLang = 'english';
  193. if (isset($_SESSION['userid'])) {
  194. $rs = $adodb->Execute("SELECT language FROM qb_user".
  195. " WHERE userid = '".$_SESSION['userid']."'");
  196. if (!$rs->EOF) $userLang = $rs->fields['language'];
  197. }
  198. $rs = $adodb->Execute("SELECT module, field, dict FROM qb_dictionary".
  199. " WHERE language = '".$userLang."'");
  200. while (!$rs->EOF) {
  201. $dictFrom = $rs->fields['field'];
  202. $dictTo = $rs->fields['dict'];
  203. $dictModule = $rs->fields['module'];
  204. $arrDictionary[strtolower($dictModule)][strtolower($dictFrom)] = $dictTo;
  205. $rs->MoveNext();
  206. }
  207. }
  208. }
  209. if (! function_exists('getMicrotime')) {
  210. function getMicrotime() {
  211. list($a,$b) = split(" ", microtime());
  212. return $a+$b;
  213. }
  214. }
  215. if (! function_exists('getTitle')) {
  216. function getTitle($file) {
  217. global $arrFILE;
  218. $file = basename($file);
  219. if (isset($arrFILE[$file])) {
  220. return __($arrFILE[$file], null, "MAIN MENU");
  221. }
  222. return $file;
  223. }
  224. }
  225. if (! function_exists('isSupervisor')) {
  226. function isSupervisor() {
  227. global $adodb;
  228. if (!isset($_SESSION['userid'])) return false;
  229. if ($_SESSION['userid'] === 'admin') return true;
  230. $rs = $adodb->Execute("SELECT * FROM qb_user ".
  231. " WHERE userid = '".$_SESSION['userid']."'");
  232. if (!$rs->EOF) {
  233. $userid = $rs->fields['userid'];
  234. $supervisor = $rs->fields['supervisor'];
  235. if (md5($userid."Yes"."qbuilder") === $supervisor) {
  236. return true;
  237. }
  238. }
  239. return false;
  240. }
  241. }
  242. if (! function_exists('isLogTable')) {
  243. function isLogTable($table) {
  244. global $adodb;
  245. $rs = $adodb->Execute("SELECT * FROM qb_setting ".
  246. " WHERE name = 'logtable' ");
  247. $value = $rs->fields['value'];
  248. $pie = explode(",", $value);
  249. if (is_int(array_search($table, $pie))) {
  250. return 'qb_changelog';
  251. } else {
  252. return false;
  253. }
  254. }
  255. }
  256. $isSupervisor = isSupervisor();
  257. /*
  258. if (isset($_SESSION['repid'])) {
  259. $rs = $adodb->Execute('SELECT pkey FROM qb_report WHERE id=' . $_SESSION['repid'] . ';');
  260. $pkey = $rs->fields['pkey'];
  261. $query3 = 'SELECT ' . $pkey . ' FROM ' . $_SESSION['reptb'] . ';';
  262. $result3 = mysql_query($query3);
  263. $row3 = @mysql_fetch_object($result3);//$result3);
  264. $identifier = '';
  265. foreach ( explode(',', $row2->pkey) as $pkey ) {
  266. if ( strlen($row3->$pkey) != 0 ) {
  267. $identifier .= $row3->$pkey;
  268. }
  269. }
  270. }
  271. */
  272. ?>