PageRenderTime 69ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/upload/libraries/core/model.php

https://github.com/sahilbabu/phpb2b
PHP | 735 lines | 657 code | 56 blank | 22 comment | 123 complexity | a118a1065cbc4222f2d45165efaf1118 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
  4. * The contents of this file are subject to the License; you may not use this file except in compliance with the License.
  5. *
  6. * @version $Revision: 2248 $
  7. */
  8. if (!class_exists('Overloadable')) {
  9. require 'overloadable.php';
  10. }
  11. class PbModel extends Overloadable
  12. {
  13. var $primaryKey = "id";
  14. var $id = null;
  15. var $catchIds = null;
  16. var $table;
  17. var $limit = 1;
  18. var $offset = 0;
  19. var $limit_offset = 1;
  20. var $dbstuff;
  21. var $table_prefix;
  22. var $condition;
  23. var $params;
  24. var $timestamp;
  25. var $dateline;
  26. var $table_name;
  27. var $orderby;
  28. var $validate = array();
  29. var $validationErrors = array();
  30. var $page_secure = false;
  31. var $cache_sql = 0;//180 seconds, if no, set 0.
  32. function PbModel()
  33. {
  34. global $pdb, $tb_prefix, $time_stamp;
  35. $this->dbstuff = &$pdb;
  36. $this->timestamp = $time_stamp;
  37. $this->table_prefix = $tb_prefix;
  38. }
  39. function call__($method, $params) {
  40. $return = $this->query($method, $params, $this);
  41. return $return;
  42. }
  43. //echo 'Your val is $name,and is not exsit in this class!';
  44. function get__($name) {}
  45. //echo 'Your val is '.$name.'=>'.$value;
  46. function set__($name, $value) {}
  47. function query() {
  48. $args = func_get_args();
  49. $fields = null;
  50. $order = null;
  51. $limit = null;
  52. $page = null;
  53. $recursive = null;
  54. if (count($args) == 1) {
  55. return $this->Execute($args[0]);
  56. }elseif (count($args) > 1 && (strpos(strtolower($args[0]), 'findby') === 0 || strpos(strtolower($args[0]), 'findallby') === 0)) {
  57. $params = $args[1];
  58. if (strpos(strtolower($args[0]), 'findby') === 0) {
  59. $all = false;
  60. $field = preg_replace('/^findBy/i', '', $args[0]);
  61. } else {
  62. $all = true;
  63. $field = preg_replace('/^findAllBy/i', '', $args[0]);
  64. }
  65. $field = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $field));
  66. $or = (strpos($field, '_or_') !== false);
  67. if ($or) {
  68. $field = explode('_or_', $field);
  69. } else {
  70. $field = explode('_and_', $field);
  71. }
  72. $off = count($field) - 1;
  73. if (isset($params[1 + $off])) {
  74. $fields = $params[1 + $off];
  75. }
  76. if (isset($params[2 + $off])) {
  77. $order = $params[2 + $off];
  78. }
  79. if (!array_key_exists(0, $params)) {
  80. return false;
  81. }
  82. $c = 0;
  83. $conditions = array();
  84. foreach ($field as $f) {
  85. $conditions[$args[2]->name . '.' . $f] = $params[$c];
  86. $c++;
  87. }
  88. if ($or) {
  89. $conditions = array('OR' => $conditions);
  90. }
  91. foreach ($conditions as $key=>$val) {
  92. $condition = $key."='".$val."'";
  93. }
  94. $fields = empty($fields)?"*":$fields;
  95. $this->setCondition($condition);
  96. $sql = "SELECT {$fields} FROM ".$this->getTable(true).$this->getCondition();
  97. unset($this->condition);
  98. return $this->dbstuff->GetRow($sql);
  99. }
  100. }
  101. function setParams($extra = array()) {
  102. $params = array();
  103. if (isset($_POST)) {
  104. $params['form'] = $_POST;
  105. if (ini_get('magic_quotes_gpc') === '1') {
  106. $params['form'] = pb_addslashes($params['form']);
  107. }
  108. if (pb_getenv('HTTP_X_HTTP_METHOD_OVERRIDE')) {
  109. $params['form']['_method'] = pb_getenv('HTTP_X_HTTP_METHOD_OVERRIDE');
  110. }
  111. if (isset($params['form']['_method'])) {
  112. if (isset($_SERVER) && !empty($_SERVER)) {
  113. $_SERVER['REQUEST_METHOD'] = $params['form']['_method'];
  114. } else {
  115. $_ENV['REQUEST_METHOD'] = $params['form']['_method'];
  116. }
  117. unset($params['form']['_method']);
  118. }
  119. }
  120. $params = array_merge($extra, $params);
  121. if (isset($_GET)) {
  122. if (ini_get('magic_quotes_gpc') === '1') {
  123. $url = stripslashes_deep($_GET);
  124. } else {
  125. $url = $_GET;
  126. }
  127. array_unique($url);
  128. if (isset($params['url'])) {
  129. $params['url'] = array_merge($params['url'], $url);
  130. } else {
  131. $params['url'] = $url;
  132. }
  133. }
  134. if (isset($params['action']) && strlen($params['action']) === 0) {
  135. $params['action'] = 'list';
  136. }
  137. if (isset($params['form']['data'])) {
  138. $params['data'] = $params['form']['data'];
  139. unset($params['form']['data']);
  140. }
  141. $this->params = $params;
  142. }
  143. function getParams()
  144. {
  145. return $this->params;
  146. }
  147. function setLimitOffset($offset, $limit)
  148. {
  149. $offset = empty($offset)?'':$offset.",";
  150. $limit = empty($limit)?1:$limit;
  151. $this->limit_offset = $offset.$limit;
  152. }
  153. function getLimitOffset()
  154. {
  155. if($this->limit_offset===0) {
  156. return;
  157. }elseif (!empty($this->limit_offset)) {
  158. return " LIMIT ".$this->limit_offset;
  159. }else{
  160. return;
  161. }
  162. }
  163. function setOrderby($orderby)
  164. {
  165. if (!$orderby || empty($orderby)) {
  166. return;
  167. }else{
  168. if (is_array($orderby)) {
  169. $tmp_str = implode(",", $orderby);
  170. }else{
  171. $tmp_str = $orderby;
  172. }
  173. $this->orderby = " ORDER BY ".$tmp_str." ";
  174. }
  175. }
  176. function getOrderby()
  177. {
  178. return $this->orderby;
  179. }
  180. function setPrimaryKey($p = null)
  181. {
  182. if (is_null($p)) {
  183. $p = "id";
  184. }
  185. $this->primaryKey = $p;
  186. }
  187. function getPrimaryKey()
  188. {
  189. return $this->primaryKey;
  190. }
  191. function setId($id)
  192. {
  193. $this->id = $id;
  194. }
  195. function getId()
  196. {
  197. return $this->id;
  198. }
  199. function del($ids, $conditions = null, $table = null)
  200. {
  201. $del_id = $this->primaryKey;
  202. $tmp_ids = $condition = null;
  203. if (is_array($ids))
  204. {
  205. $tmp_ids = implode(",",$ids);
  206. $cond[] = "{$del_id} IN ({$tmp_ids})";
  207. $this->catchIds = serialize($ids);
  208. }
  209. else
  210. {
  211. $cond[] = "{$del_id}=".intval($ids);
  212. $this->catchIds = $ids;
  213. }
  214. if (!empty($table)) {
  215. $table_name = $this->table_prefix.$table;
  216. }else{
  217. $table_name = $this->getTable();
  218. }
  219. if(!empty($conditions)) {
  220. if(is_array($conditions)) {
  221. $tmp_where_cond = implode(" AND ", $conditions);
  222. $cond[] = $tmp_where_cond;
  223. }
  224. else {
  225. $cond[] = $conditions;
  226. }
  227. }
  228. $this->setCondition($cond);
  229. $sql = "DELETE FROM ".$table_name.$this->getCondition();
  230. $deleted = $this->dbstuff->Execute($sql);
  231. unset($this->condition);
  232. return $deleted;
  233. }
  234. function save($posts, $action=null, $id=null, $tbname = null, $conditions = null, $if_check_word_ban = false)
  235. {
  236. $new_id = $result = false;
  237. $keys = array_keys($posts);
  238. $cols = implode($keys,",");
  239. $tbname = (is_null($tbname))? $this->getTable():trim($tbname);
  240. $this->table_name = $tbname;
  241. //Todo:2010.04.14, by john
  242. if(!empty($id)){
  243. $sql = "SELECT $cols FROM ".$tbname." WHERE ".$this->primaryKey."='".$id."'";
  244. }elseif(!empty($posts[$this->primaryKey])){
  245. $sql = "SELECT $cols FROM ".$tbname." WHERE ".$this->primaryKey."='".$posts[$this->primaryKey]."'";
  246. }else{
  247. $sql = "SELECT $cols FROM ".$tbname." WHERE ".$this->primaryKey."='-1'";
  248. }
  249. if (!is_null($conditions)) {
  250. if (!empty($conditions)) {
  251. if (is_array($conditions)) {
  252. $condition = implode(" AND ", $conditions);
  253. }else{
  254. $condition = $conditions;
  255. }
  256. }
  257. $sql.= " AND ".$condition;
  258. }
  259. $rs = $this->dbstuff->Execute($sql);
  260. $record = array();
  261. foreach ($keys as $colname) {
  262. $sp_search = array('\\\"', "\\\'", "'","&nbsp;", '\n','\\\&quot;');
  263. $sp_replace = array('&quot;', '&#39;', '&#39;',' ', '<br />','');
  264. $slash_col = str_replace($sp_search, $sp_replace, $posts[$colname]);
  265. if (!defined("IN_PBADMIN")) {
  266. $slash_col = sens_str($slash_col);
  267. }
  268. $record[$colname] = stripslashes(urldecode($slash_col));
  269. }
  270. if (!defined("IN_PBADMIN") && isset($record['id'])) {
  271. unset($record['id']);
  272. }
  273. if (strtolower($action) == "update") {
  274. $insertsql = $this->dbstuff->GetUpdateSQL($rs,$record);
  275. $new_id = false;
  276. }else {
  277. $insertsql = $this->dbstuff->GetInsertSQL($rs,$record);
  278. $new_id = true;
  279. }
  280. if($insertsql) $result = $this->dbstuff->Execute($insertsql);
  281. if (!$result || empty($result)) {
  282. return false;
  283. }else {
  284. if($new_id){
  285. $insert_key = $tbname."_id";
  286. $this->$insert_key = $this->dbstuff->Insert_ID();
  287. }
  288. return true;
  289. }
  290. }
  291. function read($fields = null, $id = null, $tables = null, $conditions = null)
  292. {
  293. $tmp_tablename = null;
  294. if ($id!==null) {
  295. $this->id = $id;
  296. }
  297. $id = $this->id;
  298. if (is_array($this->id)) {
  299. $id = $this->id[0];
  300. }
  301. if($tables == null){
  302. $tmp_tablename = $this->getTable(true);
  303. }
  304. if (is_null($fields)) {
  305. $fields = null;
  306. $columns = $this->dbstuff->MetaColumnNames($this->getTable());
  307. foreach ($columns as $key=>$val) {
  308. $fields.=$key." AS ".$this->name.$this->format_column($val).",";
  309. }
  310. $fields = substr_replace($fields,'',-1,1);
  311. }
  312. $sql = null;
  313. if ($this->id !== null && $this->id !== false) {
  314. $field = trim($this->name).".".$this->primaryKey;
  315. }
  316. $sql = "SELECT ".$fields." FROM ".$tmp_tablename." WHERE ".$field."='".$id."'";
  317. if(!empty($conditions)){
  318. if (is_array($conditions)) {
  319. $tmp_condition = implode(" AND ", $conditions);
  320. }else{
  321. $tmp_condition = $conditions;
  322. }
  323. $sql.= " AND ".$tmp_condition;
  324. }
  325. $res = $this->dbstuff->GetRow($sql);
  326. return $res;
  327. }
  328. function field($name, $conditions = null, $order = null) {
  329. if ($conditions === null) {
  330. $conditions = array($this->name . '.' . $this->primaryKey => $this->id);
  331. }
  332. if (is_array($conditions)) {
  333. $tmp_conditions = implode(" AND ",$conditions);
  334. $conditions = $tmp_conditions;
  335. }
  336. $sql = "select ".trim($name)." from ".$this->getTable(true)." where ".$conditions;
  337. // if ($this->cache_sql) {
  338. // $return = $this->dbstuff->CacheGetOne($this->cache_sql, $sql);
  339. // }else{
  340. $return = $this->dbstuff->GetOne($sql);
  341. // }
  342. return $return;
  343. }
  344. function getFieldAliasNames()
  345. {
  346. $table_name = $this->getTable();
  347. $fields = null;
  348. $columns = $this->dbstuff->MetaColumnNames($table_name);
  349. foreach ($columns as $key=>$val) {
  350. $fields.=$this->name.".".$key." as ".$this->name.$this->format_column($val).",";
  351. }
  352. $fields = substr_replace($fields,'',-1,1);
  353. return $fields;
  354. }
  355. function setCondition($conditions)
  356. {
  357. $return = null;
  358. if(empty($conditions)) return;
  359. if (is_array($conditions)) {
  360. $tmp_condition = implode(" AND ", $conditions);
  361. }else{
  362. $tmp_condition = $conditions;
  363. }
  364. $return = " WHERE ".$tmp_condition;
  365. $this->condition = $return;
  366. }
  367. function getCondition()
  368. {
  369. return $this->condition;
  370. }
  371. function getTable($alias = false, $join_name = '')
  372. {
  373. global $tb_prefix;
  374. $table = $tb_prefix.strtolower(get_class($this));
  375. if (!empty($join_name)) {
  376. $this->name = $join_name;
  377. }
  378. if($alias) $table.= " AS ".$this->name;
  379. return $table;
  380. }
  381. function findCount($joins = null, $conditions = null, $countfield = null, $table_alias = null)
  382. {
  383. if (!$this->page_secure) {
  384. if (isset($_GET['total_record'])) {
  385. return intval($_GET['total_record']);
  386. }elseif (isset($_GET['total_count'])){
  387. return intval($_GET['total_count']);
  388. }
  389. }
  390. $sql = $multi_table = null;
  391. if(empty($countfield)) $countfield = $this->primaryKey;
  392. if (empty($table_alias)) {
  393. $tables = $this->getTable(true);
  394. }else{
  395. $tables = $this->getTable(true, $table_alias);
  396. }
  397. if (!empty($joins)) {
  398. $multi_table = implode(" ", $joins);
  399. }
  400. $sql = "SELECT count(".$countfield.") AS amount FROM ".$tables." ".$multi_table;
  401. if (!empty($conditions)) {
  402. if (is_array($conditions) && !empty($conditions)) {
  403. $tmp_condition = implode(" AND ", $conditions);
  404. }else{
  405. $tmp_condition = $conditions;
  406. }
  407. $sql.= " WHERE ".$tmp_condition." ";
  408. }elseif (!empty($this->condition)){
  409. if (is_array($this->condition)) {
  410. $tmp_condition = implode(" AND ", $this->condition);
  411. }else{
  412. $tmp_condition = $this->condition;
  413. }
  414. $tmp_condition = str_replace("WHERE", "", $tmp_condition);
  415. $sql.= " WHERE ".$tmp_condition." ";
  416. }
  417. if ($this->cache_sql) {
  418. $return = $this->dbstuff->CacheGetOne($this->cache_sql, $sql);
  419. }else{
  420. $return = $this->dbstuff->GetOne($sql);
  421. }
  422. return $return;
  423. }
  424. function findAll($fields = null, $joins = null, $conditions = null, $order = null, $limit = null, $offset = null, $recursive = null)
  425. {
  426. global $ADODB_CACHE_DIR, $db_cache_support;
  427. $orders = null;
  428. $records = null;
  429. // $condition = null;
  430. $multi_table = null;
  431. if (is_null($fields)) {
  432. $find_fields[] = $this->name.".*";
  433. }else{
  434. $find_fields[] = $fields;
  435. }
  436. $fields = implode(",",$find_fields);
  437. if (!empty($joins)) {
  438. $multi_table = implode(" ", $joins);
  439. }
  440. $sql = "SELECT ".$fields." FROM ".$this->getTable(true)." ".$multi_table;
  441. if (!empty($conditions)) {
  442. if (is_array($conditions)) {
  443. $tmp_condition = implode(" AND ", $conditions);
  444. }else{
  445. $tmp_condition = $conditions;
  446. }
  447. $sql.= " WHERE ".$tmp_condition;
  448. }elseif (!empty($this->condition)){
  449. if (is_array($this->condition)) {
  450. $tmp_condition = implode(" AND ", $this->condition);
  451. }else{
  452. $tmp_condition = $this->condition;
  453. }
  454. $tmp_condition = str_replace("WHERE", "", $tmp_condition);
  455. $sql.= " WHERE ".$tmp_condition;
  456. }
  457. if (!empty($order)) {
  458. $orders.= " ORDER BY ".$order;
  459. $sql.= $orders;
  460. }
  461. if (!is_null($limit) && !is_null($offset)) {
  462. $records.= " LIMIT $limit,$offset";
  463. $sql.=$records;
  464. }
  465. if (!empty($ADODB_CACHE_DIR) && $this->cache_sql && !defined("IN_PBADMIN")) {
  466. $return = $this->dbstuff->CacheGetArray($sql);
  467. }else{
  468. $return = $this->dbstuff->GetArray($sql);
  469. }
  470. return $return;
  471. }
  472. function clicked($id, $additionalParams = true)
  473. {
  474. if($additionalParams){
  475. $sql = "update ".$this->getTable()." set clicked=clicked+1 where id=".$id;
  476. }
  477. return $this->dbstuff->Execute($sql);
  478. }
  479. function check($id = null, $status = 0)
  480. {
  481. if(is_array($id)){
  482. $checkId = "id in (".implode(",",$id).")";
  483. }elseif(intval($id)) {
  484. $checkId = "id=".$id;
  485. }else{
  486. return false;
  487. }
  488. $sql = "update ".$this->getTable()." set status='".$status."' where ".$checkId;
  489. $return = $this->dbstuff->Execute($sql);
  490. if($return){
  491. return true;
  492. }else {
  493. return false;
  494. }
  495. }
  496. function saveField($name, $value, $id = null, $conditions = null)
  497. {
  498. if(is_array($id)){
  499. $checkId = "id in (".implode(",",$id).")";
  500. }elseif(is_int($id)) {
  501. $checkId = "id=".$id;
  502. }else{
  503. $checkId = 1;
  504. }
  505. if(empty($conditions)) $conditions = 1;
  506. if($checkId){
  507. $sql = "update ".$this->getTable()." set $name='".$value."' where ".$checkId." and ".$conditions;
  508. $return = $this->dbstuff->Execute($sql);
  509. }
  510. return $return;
  511. }
  512. function getMaxId()
  513. {
  514. $sql = "SELECT MAX(id) FROM ".$this->getTable();
  515. $max_id = $this->dbstuff->GetOne($sql);
  516. return $max_id;
  517. }
  518. function format_column($colname)
  519. {
  520. $new_column_name = null;
  521. if (strstr($colname, "_")) {
  522. $tmp_col = explode("_", $colname);
  523. foreach ($tmp_col as $val) $new_column_name.=ucfirst(strtolower($val));
  524. }else {
  525. $new_column_name = ucfirst(strtolower($colname));
  526. }
  527. return $new_column_name;
  528. }
  529. function doValidation($arr)
  530. {
  531. if (empty($this->validate)) {
  532. return false;
  533. }
  534. $validate = array();
  535. $this->initValidations();
  536. foreach ($this->validate as $fieldName=>$val) {
  537. if ($val['required']) {
  538. if (isset($arr[$fieldName]) && empty($arr[$fieldName])) {
  539. $this->validationErrors[] = $val['message'];
  540. }
  541. }
  542. }
  543. }
  544. function initValidations()
  545. {
  546. return true;
  547. }
  548. function GetArray($sql)
  549. {
  550. global $ADODB_CACHE_DIR;
  551. //$this->dbstuff->setFetchMode(ADODB_FETCH_ASSOC);
  552. if ($this->cache_sql && !empty($ADODB_CACHE_DIR) && !defined("IN_PBADMIN")) {
  553. return $this->dbstuff->CacheGetArray($this->cache_sql, $sql);
  554. }else{
  555. return $this->dbstuff->GetArray($sql);
  556. }
  557. }
  558. function GetRow($sql)
  559. {
  560. global $ADODB_CACHE_DIR;
  561. if ($this->cache_sql && !empty($ADODB_CACHE_DIR) && !defined("IN_PBADMIN")) {
  562. return $this->dbstuff->CacheGetRow($this->cache_sql, $sql);
  563. }else{
  564. return $this->dbstuff->GetRow($sql);
  565. }
  566. }
  567. function GetAll($sql)
  568. {
  569. global $ADODB_CACHE_DIR;
  570. if ($this->cache_sql && !empty($ADODB_CACHE_DIR) && !defined("IN_PBADMIN")) {
  571. return $this->dbstuff->CacheGetAll($this->cache_sql, $sql);
  572. }else{
  573. return $this->dbstuff->GetAll($sql);
  574. }
  575. }
  576. function findIt($table_name, $parent_id = 0)
  577. {
  578. $this->dbstuff->setFetchMode(ADODB_FETCH_ASSOC);
  579. $this->params['result'] = $this->dbstuff->GetArray("SELECT * FROM ".$this->table_prefix."{$table_name} ORDER BY level ASC,id ASC");
  580. foreach ($this->params['result'] as $key=>$val) {
  581. $row = $this->getChild($val['id']);
  582. $_name = pb_lang_split($val['name']);
  583. $this->params['data'][$val['level']][$val['id']]['id'] = $val['id'];
  584. $this->params['data'][$val['level']][$val['id']]['title'] = $_name;
  585. $this->params['data'][$val['level']][$val['id']]['name'] = $_name;
  586. if (!empty($row)) {
  587. $this->params['data'][$val['level']][$val['id']]['child'] = $row;
  588. $this->params['data'][$val['level']][$val['id']]['sub'] = $row;
  589. }
  590. }
  591. }
  592. function getChild($id)
  593. {
  594. $return = array();
  595. $i = 0;
  596. foreach ($this->params['result'] as $key=>$val) {
  597. if ($val['parent_id'] == $id) {
  598. $this->params['result'][$i]['title'] = $this->params['result'][$i]['name'];
  599. $this->params['result'][$i]['name'] = $this->params['result'][$i]['name'];
  600. $return[$val['id']] = $this->params['result'][$i];
  601. }
  602. $i++;
  603. }
  604. return $return;
  605. }
  606. /**
  607. * Clean up an array, comma- or space-separated list of IDs
  608. *
  609. * @param mixed $list
  610. * @return unknown
  611. */
  612. function parseIdList( $list ) {
  613. if ( !is_array($list) )
  614. $list = preg_split('/[\s,]+/', $list);
  615. return array_unique(array_map('abs', $list));
  616. }
  617. function getIncludeIds( $list )
  618. {
  619. $include = $this->parseIdList($list);
  620. if ( is_array($include) )
  621. $include = implode(',', $include);
  622. $include = preg_replace('/[^0-9,]/', '', $include); // (int)
  623. if ( $include )
  624. return "ID IN ($include)";
  625. }
  626. function getExcludeIds( $list )
  627. {
  628. $exclude = $this->parseIdList($list);
  629. if ( is_array($exclude) )
  630. $exclude = implode(',', $exclude);
  631. $exclude = preg_replace('/[^0-9,]/', '', $exclude); // (int)
  632. if ( $exclude )
  633. return "ID NOT IN ($exclude)";
  634. }
  635. function url($params)
  636. {
  637. if (!function_exists("smarty_function_the_url")) {
  638. require(PLUGIN_PATH. "slug".DS."function.the_url.php");
  639. }
  640. return smarty_function_the_url($params);
  641. }
  642. //For static, from 2011.3.3
  643. function getPermaLink(
  644. $id,
  645. $model_url = null,
  646. $model = null,
  647. $type = "detail")
  648. {
  649. global $rewrite_able, $rewrite_compatible;
  650. $ext = ".html";
  651. if(empty($model)) {
  652. $model = strtolower($this->name);
  653. }
  654. if (!empty($model_url)) {
  655. if(strpos($model_url, ".php")===false){
  656. $model = $model_url;
  657. unset($model_url);
  658. }
  659. }
  660. if($type == "detail" && !empty($model_url)){
  661. $lbl = (strpos($model_url, "?")!==false)?"&":"?";
  662. if ($rewrite_able) {
  663. return (!empty($model_url))?$model_url.$lbl."id=".$id:$model. "/detail/".$id.$ext;
  664. }else{
  665. return (!empty($model_url))?$model_url.$lbl."id=".$id:$model."/detail.php".$lbl."id=".$id;
  666. }
  667. }
  668. }
  669. function getNeighbour($id, $fields = "*")
  670. {
  671. $ret = array();
  672. $sql_prev = "select {$fields} from ".$this->getTable()." where id<$id order by id desc limit 1";
  673. $sql_next = "select {$fields} from ".$this->getTable()." where id>$id order by id limit 1";
  674. $ret['prev'] = $this->GetRow($sql_prev);
  675. $ret['next'] = $this->GetRow($sql_next);
  676. return $ret;
  677. }
  678. }
  679. ?>