/thinkmaker/Common/common.php
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
- <?php
-
- function uplower($name) {
- return preg_replace(array("/^([a-z])/e","/_([a-zA-Z])/e"), array("strtoupper('\\1')","strtoupper('\\1')"), $name);
- }
-
-
- function getsorttype($talbe){
- if($_GET['order']==$talbe){
- if($_GET['sort']=="desc"){
- $sorttype="asc";
- }else{
- $sorttype="desc";
- }
- }else{
- $sorttype="asc";
- }
- return $sorttype;
- }
-
- function getsortimg($talbe){
-
- if($_GET['order']==$talbe){
- if($_GET['sort']=="desc"){
- $sorttype="asc";
- }else{
- $sorttype="desc";
- }
- $sortimg= '<img border="0" src="'.APP_PUBLIC_PATH.'/images/'.$sorttype.'.gif">';
- return $sortimg;
- }
- }
-
- function id_To_EValue($tb,$col,$o_col,$id){
- if(trim($id)==""){
- return "????";
- }else{
- $iddao=D($tb);
- //$iddao->Cache(true);
- $idlist=$iddao->where($o_col.'='.$id)->field($col)->find();
- return $idlist[$col];
- }
- }
-
- function getcolor($id)
- {
- if(S('color'.$id)==""){
- $thisdao=D('SubColor');
- $list=$thisdao->where('id='.$id)->field('title')->find();
- S('color'.$id,$list['title']);
- return $list['title'];
- }
- else
- {
- return S('color'.$id);
- }
- }
-
- function getfielddetail($datetype)
- {
- $field=D('SubFieldtype');
- $fielddate=$field->getbyid($datetype);
-
- if($fielddate['primary']==1){
- $date['img']='FieldKey_small.png';
- $date['iskey']=1;
- }else{
- switch ($fielddate['type']){
- case 'VARCHAR':
- $date['img']='Field_small_char.png';
- $date['iskey']=0;
- break;
- case 'TEXT':
- $date['img']='Field_small_char.png';
- $date['iskey']=0;
- break;
- case 'CHAR':
- $date['img']='Field_small_char.png';
- $date['iskey']=0;
- break;
- case 'INT':
- $date['img']='Field_small_int.png';
- $date['iskey']=0;
- break;
- case 'SMALLINT':
- $date['img']='Field_small_int.png';
- $date['iskey']=0;
- break;
- default:
- $date['img']='Field_small_char.png';
- $date['iskey']=0;
- break;
- }
- }
- $date['type']=$fielddate['type'];
- $date['leng']=$fielddate['leng'];
- //dump($date);
- return $date;
-
- }
-
- function makecontion($searchField,$searchOper,$searchString){//jqgrid????TP?????
- switch ($searchOper){
- case 'eq'://??
- $date[$searchField]=array('EQ',$searchString);
- break;
- case 'ne'://??
- $date[$searchField]=array('NEQ',$searchString);
- break;
- case 'lt'://??
- $date[$searchField]=array('LT',$searchString);
- break;
- case 'le'://?????
- $date[$searchField]=array(array('LT',$searchString),array('EQ',$searchString),'or');
- break;
- case 'gt'://??
- $date[$searchField]=array('GT',$searchString);
- break;
- case 'ge'://?????
- $date[$searchField]=array(array('GT',$searchString),array('EQ',$searchString),'or');;
- break;
- case 'bw'://???
- $date[$searchField]=array('LIKE',$searchString."%");
- break;
- case 'ew'://???
- $date[$searchField]=array('LIKE',"%".$searchString);
- break;
- case 'cn'://??
- $date[$searchField]=array('LIKE',"%".$searchString."%");
- break;
- default:
- $date[$searchField]=array('EQ',$searchString);
- break;
- }
- return $date;
- }
-
- function makeselect($name,$table,$idt='',$where='',$option='title',$f_idvalue='id',$iscache=false){
- //$option?????
- //$where?????
- //$f_idvalue???id
- //$idt????
- if($option==''){$option='title';}
- if($where==''){$where='';}
- if($idt==''){$idt='';}
- if($f_idvalue==''){$f_idvalue='id';}
- $tmp= " <select name=".$name." style='width:120px'>";
- $thisdao=D($table);
- if($iscache){
- $thisdao->Cache(true);
- }
- $list=$thisdao->where($where)->findAll();
- $tmp.= "<option >???</option>";
- foreach ($list as $row) {
- if ($idt==$row[$f_idvalue] ){$var="selected";}
- $thiscolor=getcolor($row['id']);
- $tmp.="<option value='".$row[$f_idvalue]."' ".$var." style='background:".$thiscolor.";' title='??:".$row[$f_idvalue]."??:".$row[$option]."'>".$row[$option]."</option>";
- $var='';
- $thiscolor='';
- }
-
- $tmp.= "</select>";
- return $tmp;
- }
-
- function makeoption($table,$id='id',$where='',$option='title',$order,$outadd){
- //$option?????
- //$where?????
- //$f_idvalue???id
- //$idt????
- if($option==''){$option='title';}
- if($where==''){$where='';}
- if($id==''){$id='';}
- if($order==''){$order='id desc';}
- if($outadd==''){$outadd='>';}
- $thisdao=D($table);
- //$thisdao->Cache(true);
- $options=explode(',',$option);
- $list=$thisdao->where($where)->field($option.','.$id)->order($order)->findAll();
- for ($i = 0; $i < count($list); $i++) {
- $optionkey[]=$list[$i][$id];
- foreach($options as $optionlist){
- $var.=$outadd.$list[$i][$optionlist];
- }
- $optionval[]=$var;
- $var='';
- }
- $tmp=array_combine($optionkey,$optionval);
-
- return $tmp;
- }
-
- function copytable($daoname,$inpid,$pidf='pid',$inoldid){
- //?????????????
- $daoname;//modelname
- $inpid;//???????
- $pidf;//??????[PID]
- $inoldid;//???????
-
- $table=D($daoname);//??MODEL
- $tabledata=$table->where("$pidf=$inoldid")->findall();
-
-
- foreach ($tabledata as $creatdb){
- $creatdb[$pidf]=$inpid;
- $oldid=$creatdb['id'];
- $creatdb['id']='';//clear id as null
- $table->create($creatdb);
- $table->add();
- $newid=$table->getLastInsID();
- copytable('SysFields',$newid,'pid',$oldid);
- }
-
- }
-
-
- function delbypid($daoname,$inpid,$pidf='pid'){
- $table=D($daoname);//??MODEL
- $tabledata=$table->where($pidf.'='.$inpid)->findall();//???????
- foreach ($tabledata as $creatdb){
- $oldid=$creatdb['id'];
- delbypid('SysFields',$oldid,'pid');
- }
- //$table->deleteAll('pid='.$inpid);
- $table->where('pid='.$inpid)->delete();
- }
-
- function clean_html($value){
- $value = htmlspecialchars($value, ENT_QUOTES);
- $value = strtr($value, array(
- '(' => '(',
- ')' => ')'
- ));
- return nl2br($value);
- }
-
- function un_clean_html($value){
- $value = htmlspecialchars_decode($value);
- $value = strtr($value, array(
- '(' => '(',
- ')' => ')'
- ));
- return nl2br($value);
- }
-
-
-
- function remover($string, $sep1, $sep2)
- {
- //??????????
- $len_sep1=strpos($string,$sep1);//sep1?????
- if($len_sep1===false){//??????????
- return false;
- }else{
- $leng1=strlen($sep1); //??????????
- $leng2=strlen($sep2); //???2??????
- $len_sep2=strpos($string,$sep2);//sep2?????
- $string = substr($string,$len_sep1+$leng1);//??sep2
- return $string;
- }
- }
-
- function toDate($time,$format='Y?m?d? H:i:s')
- {
- if( empty($time)) {
- return '';
- }
- $format = str_replace('#',':',$format);
- return date(auto_charset($format),$time);
- }
-
-
- function msg($info,$isok=1)
- {
- $msgtime=microtime();
- if($isok==1){
- echo "<font style='font-size:12px'>".$info."</font>";
- }else{
- echo "<font style='font-size:12px;color:red'>".$info."</font>";
- }
- echo "<a name='".$msgtime."'></a>";
- echo "<script language='JavaScript'>document.location.href='#".$msgtime."';</script>";
- ob_flush();
- flush();
- }
-
- function tpmk_dir($dir, $mode = 0755)
- {//tp?????????????,????
- if (is_dir($dir) || @mkdir($dir,$mode)) return true;
- if (!tpmk_dir(dirname($dir),$mode)) return false;
- return @mkdir($dir,$mode);
- }
-
- function tpmkdirs($dirs,$mode=0777)
- {//tp?????????????,????
- if(is_string($dirs)) {
- $dirs = explode(',',$dirs);
- }
- foreach ($dirs as $dir){
- if(!is_dir($dir)) mkdir($dir,$mode);
- }
- }
-
- ?>