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

/ourproject --username keivenlove@gmail.com/common/action.class.php

http://ourproject.googlecode.com/
PHP | 452 lines | 327 code | 61 blank | 64 comment | 42 complexity | 8ce91c3e6c0cb5c213dbc0eab30d6cf6 MD5 | raw file
  1. <?php
  2. /*
  3. * Created on 2010
  4. * Link for job@phpyun.com
  5. * This PHPYun.Rencai System Powered by PHPYun.com
  6. */
  7. class action {
  8. public $db; //??mysql
  9. public $tp; //??template
  10. public $def; //???????
  11. private $md = '321cba'; //?????????
  12. /*???*/
  13. function __construct($db, $tp, $def) {
  14. global $coding;
  15. $this->db = $db;
  16. $this->tp = $tp;
  17. $this->def = $def;
  18. $this->md = $coding;
  19. }
  20. /* ????????*/
  21. function ACT_tpfun($arr) {
  22. sort($arr); //????
  23. $this->tp->set_var($this->GET_web_con());
  24. foreach ($arr as $val) {
  25. $this->tp->set_file($val);
  26. $this->tp->n();
  27. }
  28. }
  29. /* ??????????*/
  30. function ACT_footer($value, $foot = 'footer', $debug = '') {
  31. if(is_array($value)){ //??????????
  32. foreach ($value as $val) {
  33. $this->tp->set_file($val);
  34. $this->tp->n();
  35. }
  36. }else{ //???????????
  37. $this->tp->set_file($value);
  38. $this->tp->n();
  39. }
  40. if (!empty ($foot)) {
  41. $this->tp->set_file($foot);
  42. $this->tp->n();
  43. }
  44. $this->tp->p($value);
  45. if (!empty ($debug))
  46. $this->tp->inc_list(); //??
  47. }
  48. /**
  49. * ?????
  50. * url:???? msg:???? st:0??1??2?? tm:????*/
  51. function ACT_msg($url, $msg = "??????", $st = 1, $tm = 3) {
  52. $this->tp->set_var(array (
  53. "job_arr_msg" => $msg,
  54. "job_arr_url" => $url,
  55. "job_arr_st" => $st,
  56. "job_arr_tm" => $tm));
  57. $this->tp->set_file('msg');
  58. $this->tp->p();
  59. exit ();
  60. }
  61. function ACT_user_msg($url="",$next_url="",$tm=5) {
  62. $this->tp->set_var(array (
  63. "job_url" => $url,
  64. "job_next_url" => $next_url,
  65. "job_arr_tm" => $tm));
  66. $this->tp->set_file('user_msg');
  67. $this->tp->p();
  68. exit ();
  69. }
  70. /**
  71. * ??????$tablename,$where = 1, $select="*"
  72. */
  73. function DB_select_once($tablename, $where = 1, $select = "*") {
  74. $SQL = "SELECT $select FROM " . $this->def . $tablename . " WHERE $where limit 1";
  75. $query = $this->db->query($SQL);
  76. return $this->db->fetch_array($query);
  77. }
  78. /**
  79. * ??????$tablename,$where = 1, $select="*"
  80. */
  81. function DB_select_num($tablename, $where = 1, $select = "*") {
  82. $SQL = "SELECT $select FROM " . $this->def . $tablename . " WHERE $where";
  83. $query = $this->db->query($SQL);
  84. return $this->db->db_num_rows($query);
  85. }
  86. /**
  87. * ??query?? $tablename,$where = 1, $select="*"
  88. */
  89. function DB_select_query($tablename, $where = 1, $select = "*") {
  90. $SQL = "SELECT $select FROM " . $this->def . $tablename . " WHERE $where";
  91. $query=$this->db->query($SQL);
  92. return $query;
  93. }
  94. /**
  95. * ??all?? $tablename,$where = 1, $select="*"
  96. */
  97. function DB_select_all($tablename, $where = 1, $select = "*") {
  98. $SQL = "SELECT $select FROM `" . $this->def . $tablename . "` WHERE $where";
  99. $query=$this->db->query($SQL);
  100. while($row=$this->db->fetch_array($query)){$row_return[]=$row;}
  101. return $row_return;
  102. }
  103. /**
  104. * ??all???? $tablename1,$tablename2, $where = 1, $select = "*"
  105. */
  106. function DB_select_alls($tablename1,$tablename2, $where = 1, $select = "*") {
  107. $SQL = "SELECT $select FROM " . $this->def . $tablename1. " as a," . $this->def . $tablename2 . " as b WHERE $where";
  108. $query=$this->db->query($SQL);
  109. while($row=$this->db->fetch_array($query)){$row_return[]=$row;}
  110. return $row_return;
  111. }
  112. /**
  113. * ?????? $tablename, $value
  114. */
  115. function DB_insert_once($tablename, $value) {
  116. $SQL = "INSERT INTO `" . $this->def . $tablename . "` SET $value";
  117. $this->db->query($SQL);
  118. return $this->db->insert_id($SQL);
  119. }
  120. /**
  121. * ?? $tablename, $value, $where = 1
  122. */
  123. function DB_update_all($tablename, $value, $where = 1) {
  124. $SQL = "UPDATE `" . $this->def . $tablename . "` SET $value WHERE $where";
  125. return $this->db->query($SQL);
  126. }
  127. /**
  128. * ?? $tablename, $value, $where = 1
  129. */
  130. function DB_delete_all($tablename, $where, $limit = 'limit 1') {
  131. $SQL = "DELETE FROM `" . $this->def . $tablename . "` WHERE $where $limit";
  132. return $this->db->query($SQL);
  133. }
  134. //======================????????======================================
  135. /*????*/
  136. function GET_user_shell($uid, $shell) {
  137. $query = $this->db->query("SELECT * FROM `" . $this->def . "userid` WHERE `uid`='$uid' limit 1");
  138. $us = is_array($row = $this->db->fetch_array($query));
  139. $shell = $us ? $shell == md5($row[username] . $row[password] . $this->md) : FALSE;
  140. return $shell ? $row : NULL;
  141. } //end shell
  142. function GET_user_login_index($uid, $shell){
  143. if ($row = $this->get_user_shell($uid, $shell)) {
  144. return true;
  145. } else {
  146. return false;
  147. }
  148. }
  149. /*??????*/
  150. function GET_user_shell_check($uid, $shell, $m_id = 9, $url = 'login.php') {
  151. if ($row = $this->get_user_shell($uid, $shell)) {
  152. if ($row[usertype] <= $m_id) {
  153. return $row;
  154. } else {
  155. echo "???????";
  156. exit ();
  157. } //end m_id
  158. } else {
  159. $this->ACT_msg($url, '?????');
  160. }
  161. } //end shell
  162. /**
  163. * ????
  164. */
  165. function Get_user_login($username, $password, $urlture = 'usermanage.php', $urlfalse = 'login.php') {
  166. $username = str_replace(" ", "", $username);
  167. $query = $this->db->query("SELECT * FROM `" . $this->def . "userid` WHERE `username`='$username' limit 1");
  168. $us = is_array($row = $this->db->fetch_array($query));
  169. $ps = $us ? md5($password) == $row[password] : FALSE;
  170. if ($ps) {
  171. SetCookie("uid", $row[uid], time() + 80000, "/");
  172. SetCookie("username", $row[username], time() + 80000, "/");
  173. SetCookie("shell", md5($row[username] . $row[password] . $this->md), time() + 80000, "/");
  174. $this->DB_update_all("userid", "`date_login`='" . mktime() . "',`iponline`='" . $this->db->fun_ip_get() . "'", "`uid`='$row[uid]'");
  175. if ($urlture)
  176. $this->ACT_msg($urlture, '?????');
  177. } else {
  178. $this->ACT_msg($urlfalse, '????????');
  179. }
  180. }
  181. /**
  182. * ??????
  183. */
  184. public function Get_user_out($url = 'login.php') {
  185. SetCookie("uid", "", time() - 80000, "/");
  186. SetCookie("shell", "", time() - 80000, "/");
  187. $this->ACT_msg($url, '?????');
  188. }
  189. //======================????????======================================
  190. /*????*/
  191. function GET_com_shell($uid, $shell) {
  192. $query = $this->db->query("SELECT * FROM `" . $this->def . "comid` WHERE `uid`='$uid' limit 1");
  193. $us = is_array($row = $this->db->fetch_array($query));
  194. $shell = $us ? $shell == md5($row[username] . $row[password] . $this->md) : FALSE;
  195. return $shell ? $row : NULL;
  196. } //end shell
  197. function GET_com_login_index($uid,$shell){
  198. if ($row = $this->get_com_shell($uid,$shell)) {
  199. return true;
  200. } else {
  201. return false;
  202. }
  203. }
  204. /*??????*/
  205. function GET_com_shell_check($uid, $shell, $m_id = 9, $url = 'logins.php') {
  206. if ($row = $this->get_com_shell($uid, $shell)) {
  207. if ($row[usertype] <= $m_id) {
  208. return $row;
  209. } else {
  210. echo "???????";
  211. exit ();
  212. } //end m_id
  213. } else {
  214. $this->ACT_msg($url, '?????');
  215. }
  216. } //end shell
  217. function com_type($comuid){
  218. $com=$this->DB_select_once("comid","`uid`='$comuid'");
  219. $time=($com[vip_time]-mktime())/86400;
  220. if($com[usertype]==2 && $time>=120 && $time<365){
  221. $type=3;
  222. }elseif($com[usertype]==3 && $time>365){
  223. $type=4;
  224. }elseif($time>=365){
  225. $type=4;
  226. }else{
  227. $type=$com[usertype];
  228. }
  229. return $type;
  230. }
  231. /**
  232. * ????
  233. */
  234. function Get_com_login($username, $password, $urlture = 'commanage.php', $urlfalse = 'logins.php') {
  235. $username = str_replace(" ", "", $username);
  236. $query = $this->db->query("SELECT * FROM `" . $this->def . "comid` WHERE `username`='$username' limit 1");
  237. $us = is_array($row = $this->db->fetch_array($query));
  238. $ps = $us ? md5($password) == $row[password] : FALSE;
  239. //???
  240. if($us){
  241. if ($ps) {
  242. if($row[usertype]==0){
  243. $this->ACT_msg($urlfalse, '????????');
  244. }else{
  245. SetCookie("cuid", $row[uid], time() + 80000, "/");
  246. SetCookie("cusername", $row[username], time() + 80000, "/");
  247. SetCookie("cshell", md5($row[username] . $row[password] . $this->md), time() + 80000, "/");
  248. if($row[usertype]>1){
  249. if($row[vip_time]<mktime()){
  250. $where="`vip_time`='0',`usertype`='1',";
  251. }else{
  252. $where="`usertype`=".$this->com_type($row[uid]).",";
  253. }
  254. }else{
  255. $where=null;
  256. }
  257. $this->DB_update_all("comid", "$where `date_login`='" . mktime() . "',`iponline`='" . $this->db->fun_ip_get() . "'", "`uid`='$row[uid]'");
  258. if ($urlture)
  259. $this->ACT_msg($urlture, '?????');
  260. }
  261. } else {
  262. $this->ACT_msg($urlfalse, '????????');
  263. }
  264. }else{
  265. $this->ACT_msg("registers.php", '???????,?????');
  266. }
  267. }
  268. /**
  269. * ??????
  270. */
  271. public function Get_com_out($url = 'logins.php') {
  272. SetCookie("cuid", "", time() - 80000, "/");
  273. SetCookie("cshell", "", time() - 80000, "/");
  274. $this->ACT_msg($url, '?????');
  275. }
  276. //==========================????===============================
  277. /**
  278. * ??????
  279. */
  280. function GET_web_con() {
  281. $query = $this->DB_select_all("admin_config");
  282. foreach($query as $v){ $con_row[$v[0]]=$v[1];}
  283. return $con_row;
  284. }
  285. /**
  286. * ??????
  287. */
  288. function news_class($table,$where){
  289. $query = $this->DB_select_all($table,$where);
  290. if($query[0][0]){
  291. foreach($query as $v){$newsclass.=$v[0].",";}
  292. }
  293. return $newsclass;
  294. }
  295. function advertise($where,$num){
  296. $query=$this->DB_select_all("advertise","`position`='$where' and `edate`>='".mktime()."' order by priority desc limit $num");
  297. return $query;
  298. }
  299. function user_complete($num){
  300. switch($num){
  301. case 0:
  302. $numresume=$numresume+0;
  303. break;
  304. case 1:
  305. $numresume=$numresume+5;
  306. break;
  307. case 2:
  308. $numresume=$numresume+10;
  309. break;
  310. default:
  311. $numresume=$numresume+12.5;
  312. break;
  313. }
  314. return $numresume;
  315. }
  316. function complete($eid,$useruid){
  317. $user_resume = $this->DB_select_once("user_resume", "`eid`='$eid' and `uid`='$useruid'");
  318. if($user_resume[expect]==1){
  319. $numresume=10;
  320. }
  321. $numresume=$numresume+$this->user_complete($user_resume[skill]);
  322. $numresume=$numresume+$this->user_complete($user_resume[work]);
  323. $numresume=$numresume+$this->user_complete($user_resume[project]);
  324. $numresume=$numresume+$this->user_complete($user_resume[edu]);
  325. $numresume=$numresume+$this->user_complete($user_resume[training]);
  326. $numresume=$numresume+$this->user_complete($user_resume[cert]);
  327. $numresume=$numresume+$this->user_complete($user_resume[other]);
  328. return $numresume;
  329. }
  330. function GET_web_url(){
  331. $url=explode("/",$_SERVER["REQUEST_URI"]);
  332. if($url[2]=="news"){
  333. $value= "../";
  334. }elseif($url[1]=="news"){
  335. $value= "../";
  336. }else{
  337. $value="./";
  338. }
  339. return $value;
  340. }
  341. function GET_web_key($key=1){
  342. if($key!=1){
  343. $config=$this->GET_web_con();
  344. $value=$config[$key];
  345. }
  346. return $value;
  347. }
  348. function GET_web_des($con){
  349. return substr(str_replace(array("\r","\n"),array(" "," "),strip_tags($con)),0,200);
  350. }
  351. function GET_web_news($id,$type=1){
  352. if($type==2){
  353. $where="`id`>'$id'";
  354. }else{
  355. $where="`id`<'$id' order by id desc";
  356. }
  357. $con=$this->DB_select_once("news_base",$where,"`id`,`title`");
  358. return $con;
  359. }
  360. function GET_web_action($value){
  361. //$value=str_replace(array("../","%","jpg","."),array("","","",""),$value);
  362. if(preg_match("/^[a-zA-Z0-9]+$/",$value,$arr)){
  363. return $value;
  364. }else{
  365. header("location:index.php");
  366. }
  367. }
  368. //uc??
  369. function GET_uc_other($action,$name,$pwd,$email){
  370. include ("./app/ucenter/config.php"); //UC ????
  371. include ("./app/ucenter/client.php"); //UC ???
  372. include ("./app/ucenter/api/uc.php"); //UC ???
  373. define('UC_LINK','TRUR');
  374. if($action=="reg"){
  375. return uc_user_register($name,$pwd,$email);}
  376. if($action=="login"){
  377. $value=uc_user_login($name,$pwd,$email);
  378. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  379. setcookie('uchome_auth',authcode($value[0].$value[1],'ENCODE'));
  380. //echo $_COOKIE['uchome_auth'];
  381. $ucsynlogin =synlogin($value[0]);
  382. return $value;
  383. }
  384. }
  385. function GET_web_process($action="reg",$type="ucenter",$name,$pwd,$email=""){
  386. if($type=="ucenter"){
  387. return $this->GET_uc_other($action,$name,$pwd,$email);
  388. }
  389. }
  390. } //end class
  391. ?>