PageRenderTime 88ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/thinkmaker/Common/common.php

http://iiccms.googlecode.com/
PHP | 304 lines | 257 code | 33 blank | 14 comment | 29 complexity | 45d9ac5bf40603d470dffd4ee820d23f MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. function uplower($name) {
  3. return preg_replace(array("/^([a-z])/e","/_([a-zA-Z])/e"), array("strtoupper('\\1')","strtoupper('\\1')"), $name);
  4. }
  5. function getsorttype($talbe){
  6. if($_GET['order']==$talbe){
  7. if($_GET['sort']=="desc"){
  8. $sorttype="asc";
  9. }else{
  10. $sorttype="desc";
  11. }
  12. }else{
  13. $sorttype="asc";
  14. }
  15. return $sorttype;
  16. }
  17. function getsortimg($talbe){
  18. if($_GET['order']==$talbe){
  19. if($_GET['sort']=="desc"){
  20. $sorttype="asc";
  21. }else{
  22. $sorttype="desc";
  23. }
  24. $sortimg= '<img border="0" src="'.APP_PUBLIC_PATH.'/images/'.$sorttype.'.gif">';
  25. return $sortimg;
  26. }
  27. }
  28. function id_To_EValue($tb,$col,$o_col,$id){
  29. if(trim($id)==""){
  30. return "????";
  31. }else{
  32. $iddao=D($tb);
  33. //$iddao->Cache(true);
  34. $idlist=$iddao->where($o_col.'='.$id)->field($col)->find();
  35. return $idlist[$col];
  36. }
  37. }
  38. function getcolor($id)
  39. {
  40. if(S('color'.$id)==""){
  41. $thisdao=D('SubColor');
  42. $list=$thisdao->where('id='.$id)->field('title')->find();
  43. S('color'.$id,$list['title']);
  44. return $list['title'];
  45. }
  46. else
  47. {
  48. return S('color'.$id);
  49. }
  50. }
  51. function getfielddetail($datetype)
  52. {
  53. $field=D('SubFieldtype');
  54. $fielddate=$field->getbyid($datetype);
  55. if($fielddate['primary']==1){
  56. $date['img']='FieldKey_small.png';
  57. $date['iskey']=1;
  58. }else{
  59. switch ($fielddate['type']){
  60. case 'VARCHAR':
  61. $date['img']='Field_small_char.png';
  62. $date['iskey']=0;
  63. break;
  64. case 'TEXT':
  65. $date['img']='Field_small_char.png';
  66. $date['iskey']=0;
  67. break;
  68. case 'CHAR':
  69. $date['img']='Field_small_char.png';
  70. $date['iskey']=0;
  71. break;
  72. case 'INT':
  73. $date['img']='Field_small_int.png';
  74. $date['iskey']=0;
  75. break;
  76. case 'SMALLINT':
  77. $date['img']='Field_small_int.png';
  78. $date['iskey']=0;
  79. break;
  80. default:
  81. $date['img']='Field_small_char.png';
  82. $date['iskey']=0;
  83. break;
  84. }
  85. }
  86. $date['type']=$fielddate['type'];
  87. $date['leng']=$fielddate['leng'];
  88. //dump($date);
  89. return $date;
  90. }
  91. function makecontion($searchField,$searchOper,$searchString){//jqgrid????TP?????
  92. switch ($searchOper){
  93. case 'eq'://??
  94. $date[$searchField]=array('EQ',$searchString);
  95. break;
  96. case 'ne'://??
  97. $date[$searchField]=array('NEQ',$searchString);
  98. break;
  99. case 'lt'://??
  100. $date[$searchField]=array('LT',$searchString);
  101. break;
  102. case 'le'://?????
  103. $date[$searchField]=array(array('LT',$searchString),array('EQ',$searchString),'or');
  104. break;
  105. case 'gt'://??
  106. $date[$searchField]=array('GT',$searchString);
  107. break;
  108. case 'ge'://?????
  109. $date[$searchField]=array(array('GT',$searchString),array('EQ',$searchString),'or');;
  110. break;
  111. case 'bw'://???
  112. $date[$searchField]=array('LIKE',$searchString."%");
  113. break;
  114. case 'ew'://???
  115. $date[$searchField]=array('LIKE',"%".$searchString);
  116. break;
  117. case 'cn'://??
  118. $date[$searchField]=array('LIKE',"%".$searchString."%");
  119. break;
  120. default:
  121. $date[$searchField]=array('EQ',$searchString);
  122. break;
  123. }
  124. return $date;
  125. }
  126. function makeselect($name,$table,$idt='',$where='',$option='title',$f_idvalue='id',$iscache=false){
  127. //$option?????
  128. //$where?????
  129. //$f_idvalue???id
  130. //$idt????
  131. if($option==''){$option='title';}
  132. if($where==''){$where='';}
  133. if($idt==''){$idt='';}
  134. if($f_idvalue==''){$f_idvalue='id';}
  135. $tmp= " <select name=".$name." style='width:120px'>";
  136. $thisdao=D($table);
  137. if($iscache){
  138. $thisdao->Cache(true);
  139. }
  140. $list=$thisdao->where($where)->findAll();
  141. $tmp.= "<option >???</option>";
  142. foreach ($list as $row) {
  143. if ($idt==$row[$f_idvalue] ){$var="selected";}
  144. $thiscolor=getcolor($row['id']);
  145. $tmp.="<option value='".$row[$f_idvalue]."' ".$var." style='background:".$thiscolor.";' title='??:".$row[$f_idvalue]."??:".$row[$option]."'>".$row[$option]."</option>";
  146. $var='';
  147. $thiscolor='';
  148. }
  149. $tmp.= "</select>";
  150. return $tmp;
  151. }
  152. function makeoption($table,$id='id',$where='',$option='title',$order,$outadd){
  153. //$option?????
  154. //$where?????
  155. //$f_idvalue???id
  156. //$idt????
  157. if($option==''){$option='title';}
  158. if($where==''){$where='';}
  159. if($id==''){$id='';}
  160. if($order==''){$order='id desc';}
  161. if($outadd==''){$outadd='>';}
  162. $thisdao=D($table);
  163. //$thisdao->Cache(true);
  164. $options=explode(',',$option);
  165. $list=$thisdao->where($where)->field($option.','.$id)->order($order)->findAll();
  166. for ($i = 0; $i < count($list); $i++) {
  167. $optionkey[]=$list[$i][$id];
  168. foreach($options as $optionlist){
  169. $var.=$outadd.$list[$i][$optionlist];
  170. }
  171. $optionval[]=$var;
  172. $var='';
  173. }
  174. $tmp=array_combine($optionkey,$optionval);
  175. return $tmp;
  176. }
  177. function copytable($daoname,$inpid,$pidf='pid',$inoldid){
  178. //?????????????
  179. $daoname;//modelname
  180. $inpid;//???????
  181. $pidf;//??????[PID]
  182. $inoldid;//???????
  183. $table=D($daoname);//??MODEL
  184. $tabledata=$table->where("$pidf=$inoldid")->findall();
  185. foreach ($tabledata as $creatdb){
  186. $creatdb[$pidf]=$inpid;
  187. $oldid=$creatdb['id'];
  188. $creatdb['id']='';//clear id as null
  189. $table->create($creatdb);
  190. $table->add();
  191. $newid=$table->getLastInsID();
  192. copytable('SysFields',$newid,'pid',$oldid);
  193. }
  194. }
  195. function delbypid($daoname,$inpid,$pidf='pid'){
  196. $table=D($daoname);//??MODEL
  197. $tabledata=$table->where($pidf.'='.$inpid)->findall();//???????
  198. foreach ($tabledata as $creatdb){
  199. $oldid=$creatdb['id'];
  200. delbypid('SysFields',$oldid,'pid');
  201. }
  202. //$table->deleteAll('pid='.$inpid);
  203. $table->where('pid='.$inpid)->delete();
  204. }
  205. function clean_html($value){
  206. $value = htmlspecialchars($value, ENT_QUOTES);
  207. $value = strtr($value, array(
  208. '(' => '&#40;',
  209. ')' => '&#41;'
  210. ));
  211. return nl2br($value);
  212. }
  213. function un_clean_html($value){
  214. $value = htmlspecialchars_decode($value);
  215. $value = strtr($value, array(
  216. '&#40;' => '(',
  217. '&#41;' => ')'
  218. ));
  219. return nl2br($value);
  220. }
  221. function remover($string, $sep1, $sep2)
  222. {
  223. //??????????
  224. $len_sep1=strpos($string,$sep1);//sep1?????
  225. if($len_sep1===false){//??????????
  226. return false;
  227. }else{
  228. $leng1=strlen($sep1); //??????????
  229. $leng2=strlen($sep2); //???2??????
  230. $len_sep2=strpos($string,$sep2);//sep2?????
  231. $string = substr($string,$len_sep1+$leng1);//??sep2
  232. return $string;
  233. }
  234. }
  235. function toDate($time,$format='Y?m?d? H:i:s')
  236. {
  237. if( empty($time)) {
  238. return '';
  239. }
  240. $format = str_replace('#',':',$format);
  241. return date(auto_charset($format),$time);
  242. }
  243. function msg($info,$isok=1)
  244. {
  245. $msgtime=microtime();
  246. if($isok==1){
  247. echo "<font style='font-size:12px'>".$info."</font>";
  248. }else{
  249. echo "<font style='font-size:12px;color:red'>".$info."</font>";
  250. }
  251. echo "<a name='".$msgtime."'></a>";
  252. echo "<script language='JavaScript'>document.location.href='#".$msgtime."';</script>";
  253. ob_flush();
  254. flush();
  255. }
  256. function tpmk_dir($dir, $mode = 0755)
  257. {//tp?????????????,????
  258. if (is_dir($dir) || @mkdir($dir,$mode)) return true;
  259. if (!tpmk_dir(dirname($dir),$mode)) return false;
  260. return @mkdir($dir,$mode);
  261. }
  262. function tpmkdirs($dirs,$mode=0777)
  263. {//tp?????????????,????
  264. if(is_string($dirs)) {
  265. $dirs = explode(',',$dirs);
  266. }
  267. foreach ($dirs as $dir){
  268. if(!is_dir($dir)) mkdir($dir,$mode);
  269. }
  270. }
  271. ?>