curFile=$fp; } function ceckFile(){ $this->ex=file_exists($this->curFile); return $this->ex; } function getPeso(){ $this->peso=filesize($this->curFile); $this->peso=round(($this->peso/1000)).' kb'; if($this->peso>999) $this->peso=($this->peso/1000).' Mb'; return $this->peso; } function getExt(){ $this->ext=filetype($this->curFile); return $this->ext; } function round(){ $this->getExt(); $this->ext; } function getImma_W(){ $size = getimagesize ($this->curFile); return $this->imma_W=$size[0]; } function getImma_H(){ $size = getimagesize ($this->curFile); return $this->imma_H=$size[1]; } function getLastMod() { return date ("d-m-Y", filemtime($this->curFile)); } function ma_copy_file($file,$newFile) { if (!copy($file, $newFile)) { $this->msg= "Errore nella copia di $file...\n"; } else { $this->msg= "Il file $newFile è stato creato..\n"; } } } class creafile extends get_File { function writefile($data){ // open file $fh = fopen($this->filename, "w") or die("Could not open file!"); // write to file fwrite($fh,$data) or die("Could not write to file"); // close file fclose($fh); } function setFilePath($filename){ $root=$this->getRoot(); $this->filename=$root.$filename; return $this->filename; } //setto la root function getRoot() { $root=$_SERVER["DOCUMENT_ROOT"]; return $this->root=$root; } function appendDataTofile($data) { //Imports old data $handle = fopen($filename, "r"); $old_content = fread($handle, filesize ($this->filename)); fclose($handle); //Sets up new data $final_content = $data.$old_content; //Writes new data $handle2 = fopen($this->filename, "w"); $finalwrite = fwrite($handle2, $final_content); fclose($handle2); } } ?>query="SELECT DISTINCT ".$field." as a,".$field2." as b FROM ".$tab." ".$where. " Group by ".$field." order By ".$orderBy; return $this->query; } // funzione generica che prende i dati da una tabella function getTable($a,$b,$tab,$whereV='',$whereF='',$order='',$mode=0,$flagOb=''){ $where=(!empty($whereF))?"where ".$whereF."='".$whereV."'":""; if($mode==1)$where=" where ".$whereF."=".$whereV; if($mode==2)$where=" where ".$whereF."!='".$whereV."'"; if($mode==3)$where=" where ".$whereF." "; $order=(!empty($order))?" order by ".$order:""; if(empty($where))$where=" where 1"; if(!empty($flagOb))$where.=" and FlagOb=0"; $this->query="SELECT ".$a." as a, ".$b." as b FROM ".$tab." ".$where.$order; return $this->query; } //function debugg function debug(){ echo $this->query."
"; } } class combo extends comboConf { var $name; var $Quick; var $Inv; var $Mode;// setto il modo doppio, triplo etc // setto nome della combo function setName($name){ $this->name=$name; return $this->name; } function setInv() { $this->Inv=1; return $this->Inv; } function setMode($curMode) { // 2 doppio // 3 triplo // 4 array e non obj $this->Mode=$curMode; return $this->Mode; } // funzioni per le combo //vi valori sono array da ciclare=$res, $curItem=item corrente per la selezione $name=metto anche il nome della selct, $inv=slection inversa se o uso il rs a altrimenti il res b function makeSimpleCombo($res,$curItem,$tipo='',$stringaSel=''){ $this->w_C=''; if(!empty($res) ){ $this->getName(); $this->getQuick(); if($tipo=='stringa')$res=explode(',',$res); foreach ($res as $re){ //if(!is_object($re)) echo $re.'[]
'; // inverto $rea=$re->a; $reb=$re->b; if(is_array($curItem)){ $rea=$re->a; $reb=$re->b; if($this->Inv)$sel=(in_array($re->a,$curItem))?$sel="SELECTED":""; else$sel=(in_array($re->b,$curItem))?$sel="SELECTED":""; } else if($tipo=='stringa'){ $re=split('#',$re); $rea=$re[0]; $reb=(!empty($re[1]))?$re[1]:$re[0]; if(!empty($stringaSel)){$sel=($re[0]==$curItem)?$sel="SELECTED":""; } else { $sel=($reb==$curItem)?$sel="SELECTED":""; } } else { $rea=$re->a; $reb=$re->b; if($this->Inv)$sel=($re->a==$curItem)?$sel="SELECTED":""; else$sel=($re->b==$curItem)?$sel="SELECTED":""; } //pulisci $reaP=stripslashes($re->a); $rebP=stripslashes($re->b); $rea=stripslashes($rea); $reb=stripslashes($reb); $this->w_C.="\n"; if($this->Mode==2)$this->w_C.=''; else if($this->Mode==3)$this->w_C.=''; else if($this->Mode==4)$this->w_C.=''; else if($this->Mode==6)$this->w_C.=''; else if($this->Mode==5)$this->w_C.=''; else $this->w_C.=''; } if($this->name)$this->w_C.="\n"; return $this->w_C; } } //restituisce il blocco di codice crea il nome function getName(){ $this->name=(!empty($this->name))?'name="'.$this->name.'"':''; return $this->name; } // setto se metto opzione scegli function setQuick_________to_delete(){ $this->Quick=1; return $this->Quick; } function getQuick(){ $this->Quick=(!empty($this->Quick))?'':''; return $this->Quick; } } // classe che mi costruisce il where class where { function setWhere($where){ $this->where=$where; return $this->where; } // aggiunge la string al where function addWhere($string){ $this->where=(!empty($this->where))?$this->where." and ".$string." ":"where ".$string." "; return $this->where; } // aggiunge la string al where function setMacth($field,$string,$isBool=0,$isString=0){ $string=trim($string); if($isString==1)$this->where=''; else $this->where=(!empty($this->where))?$this->where." and ":" where "; if($isBool=1) { $stringArr=explode(' ',$string); array_unique($stringArr); //print_r($stringArr); if(count($stringArr)>0) { foreach($stringArr as $s) { if(strlen($s)>3) { if($stringQuery!='')$stringQuery.=' '; $stringQuery.='+'.$s.'*'; } } } //print_r($stringArr); //$string=implode(' ',$stringArr); $this->where.="MATCH(".$field.") AGAINST('".$stringQuery."' IN BOOLEAN MODE)"; } else $this->where.="MATCH(".$field.") AGAINST('".$string."')"; return $this->where; } function setDiv($a,$b){ $this->where=(!empty($this->where))?$this->where." and ".$a."!=".$b:"where ".$a."!=".$b; return $this->where; } function setF_I_S($a,$b){ $this->where=(!empty($this->where))?$this->where." and ":" where "; $this->where.="FIND_IN_SET('".$b."',".$a.")"; return $this->where; } function setLike($a,$b){ $this->where=(!empty($this->where))?$this->where." and ".$a." like '%".$b."%'":"where ".$a." like '%".$b."%'"; return $this->where; } function setEq($a,$b){ $this->where=(!empty($this->where))?$this->where." and ".$a."='".$b."'":"where ".$a."='".$b."'"; return $this->where; } function setEqN($a,$b){ $this->where=(!empty($this->where))?$this->where." and ".$a."=".$b:"where ".$a."=".$b; return $this->where; } function setBet($a,$b,$c){ $this->where=(!empty($this->where))?$this->where." and ".$a." BETWEEN ".$b." and ".$c:"where ".$a." BETWEEN ".$b." and ".$c; return $this->where; } function setMin($a,$b){ $this->where=(!empty($this->where))?$this->where." and ".$a."<='".$b."'":"where ".$a."<'".$b."'"; return $this->where; } function setMagg($a,$b,$deli="'"){ $this->where=(!empty($this->where))?$this->where." and ".$a.">=".$deli.$b.$deli:"where ".$a."<".$deli.$b.$deli; return $this->where; } function setDif($a,$start=0,$stop=30,$from="NOW()"){ $where=(!empty($this->where))?" and ":"Where "; $this->where=$this->where.$where."TO_DAYS(".$a.") - TO_DAYS(".$from.") >=".$start." and TO_DAYS(".$a.") - TO_DAYS(".$from.") < ".$stop; return $this->where; } // giorni di differenza function setDay($a="NOW()",$b,$day='10'){ $where=(!empty($this->where))?" and ":"Where "; $this->where=$this->where.$where."(TO_DAYS(".$a.")-TO_DAYS(".$b.")) >10"; return $this->where; } // null function setNull($a){ $where=(!empty($this->where))?" and ":"Where "; $this->where=$this->where.$where." ". $a ." is NULL"; return $this->where; } // null function setNotNull($a){ $where=(!empty($this->where))?" and ":"Where "; $this->where=$this->where.$where." ". $a ." is NOT NULL"; return $this->where; } function setOr($a){ $where=(!empty($this->where))?" and ":"Where "; $this->where=$this->where.$where." (".$a.")"; return $this->where; } // fucntion set Periodo // data Su // giorni di differenza function setDataSub($a,$b,$c="MONTH"){ $where=(!empty($this->where))?" and ":"Where "; $this->where=$this->where.$where." ".$a." > DATE_SUB(NOW(), INTERVAL ".$b." ".$c." )"; return $this->where; } // ciclo per combo con multi scelta function setEqArr($a,$b,$num='',$value=''){ $num; $this->where=(!empty($this->where))?$this->where." and (": " where ("; $i=0; $curEle=''; foreach($b as $data){ if($i!=0)$this->where.=" or "; if($value)$this->where.=$a.$data."='".$value."'"; // verifico se il valore del campo � uguale a quello che passo else if($num)$this->where.=$a.$data."='".$data."'"; // incremento il valor del campo else $this->where.=$a."='".$data."'"; $i++; } $this->where.=')'; return $this->where; } // array Mix $a=campo, $b= array valori, $extra= campo opzionale se il contenuto e testo function setIN($a,$b,$extra=''){ $this->where=(!empty($this->where))?$this->where." and (": " where ("; foreach ($b as $data){ //se numero aggiungo if(is_numeric($data)){ if($n)$n.=','.$data; //metto la virgola else $n.=$data; // se il primo non metto la virgola } // altrimenti alla lista delle lettere else { if($s)$s.=","; $s.="'".$data."'"; } } if($n){ $this->where.=$a.' IN ('.$n.') '; if($s) $this->where.=' or '; } if($s)$this->where.=' '.$extra.' IN ('.$s.')'; $this->where.=')'; return $this->where; } function setNOTIN($a,$b,$extra=''){ $this->where=(!empty($this->where))?$this->where." and (": " where ("; foreach ($b as $data){ //se numero aggiungo if(is_numeric($data)){ if($n)$n.=','.$data; //metto la virgola else $n.=$data; // se il primo non metto la virgola } // altrimenti alla lista delle lettere else { if($s)$s.=","; $s.="'".$data."'"; } } if($n){ $this->where.=$a.' NOT IN ('.$n.') '; if($s) $this->where.=' or '; } if($s)$this->where.=' '.$extra.' NOT IN ('.$s.')'; $this->where.=')'; return $this->where; } // setto doppio array function setEqDoubleArr($tab,$a,$b){ $this->where=(!empty($this->where))?$this->where." and (": " where ("; $i=0; $curEle=''; foreach($b as $data){ if($i!=0)$this->where.=" or "; $this->where.=$tab.".".$a[$i]."='".$data."'"; $i++; } $this->where.=')'; return $this->where; } // multi scelta multi field function setEqArrMulti($a,$b,$n){ $this->where=(!empty($this->where))?$this->where." and (": " where ("; $i=0; $curEle=''; foreach($b as $data){ if($i!=0)$this->where.=" or "; for($el=1;$el<=$n;$el++){ if($el!=1)$this->where.=" or "; $this->where.=$a.$el."='".$data."'"; } $i++; } $this->where.=')'; return $this->where; } // multi scelta multi field like function setLikeArrMulti($a,$b,$n){ $this->where=(!empty($this->where))?$this->where." and (": " where ("; $i=0; $curEle=''; foreach($b as $data){ if($i!=0)$this->where.=" or "; for($el=1;$el<=$n;$el++){ if($el!=1)$this->where.=" or "; $this->where.=$a.$el." like '%".$data."%'"; } $i++; $i; } $this->where.=')'; return $this->where; } // // ritorna il where function getWhere(){ $this->where; return $this->where; } } // class che fa il group by class groupBy { function setGroup($group){ $this->group=" group by ". $group; return $this->group; } } class ordina { var $order; var $defOrderr; var $sortaMode; //setto il sort function setdefOrder($defOrder){ $this->defOrder=(!empty($this->order))?' ,'.$defOrder:$defOrder; return $this->defOrder; } function setOrder($order){ $this->order=$order; return $this->order; } function getMode(){ $this->sortaMode=(empty($_GET["ordinaMode"]))?" ":$_GET["ordinaMode"]; return $this->sortaMode; } //setto il mode function setMode(){ $this->Mode=($this->sortaMode=='DESC')?"":"DESC"; return $this->Mode; } // faccio il sort function get0rder(){ $this->sorta=" Order By ".$this->order." ".$this->sortaMode." ".$this->defOrder; return $this->sorta; } } class ordinaHeader extends ordina { //riistanzo il constructor princiaple function setOrder($order){ $this->order=$order; return $this->order; } // funzione che fa l'etichetta function makeHeader($label,$type){ $full_path=split("&sort=",getenv("REQUEST_URI")); if($type==$this->order)$this->setMode(); else $this->Mode=""; $this->label=''.$label.''; return $this->label; } } // classe per una ricerca semplice di una sola parola class cerca{ var $data; var $nW; // set parameter function setData($data,$where){ $this->data=addslashes($data); $this->w= new Where; $this->w->setWhere($where); } //becco le colonne se contengono un alias prendo solo la prima parte function getCol(){ $this->col = explode(",", $this->data); return $this->col; } // costruisco il where function getWhere(){ return $this->wSearch=$this->w->getWhere(); } // costruisco il where function setWhereLike(){ if($this->wSearch=="")$where=" Where "; else $where.=$this->wSearch." and ("; $this->where=$where; return $this->where; } function getQueryLike($curParola){ $this->getWhere(); $this->setWhereLike(); $this->getCol(); $i=0; foreach($this->col as $c ){ $this->pulisci($c); $cp=$this->cS; if($i!=0)$this->where.=" or "; $this->where.=$cp ." LIKE '%".$curParola."%'" ; $i++; } if($this->wSearch!="")$this->where.=')'; $this->w->setWhere($this->where); } // gestiscele queri normali function getQuery(){ $this->getCol(); foreach($this->col as $c ){ $cField=str_replace('.','_',$c); if(ma_not_null(ma_getParameter($cField))){ $this->w->setEq($c,ma_getParameter($cField)); } } } // pulisci la stringa se contiene un as function pulisci($str){ $cS=split(' as ',$str); $curFiled=split(')',trim($cS[0])); $pos=strpos($curFiled[0], "oncat"); if($pos){} else { return $this->cS=$curFiled[0]; } } } class ckTable{ function ckTable($val){ global $db; $this->db=$db; $this->val=explode(',',$val); } function createHTML($campo,$col=3,$linka=0,$id=0,$w=0){ $i=1; foreach($this->Lista as $d){ $field=$campo.'['.$d->a.']'; $ce=(in_array ($d->a, $this->val))?1:0; if($linka==1)$d->b=$this->createLink($d->b,$i); if($linka==2)$d->b=$this->createLink($d->b,$campo."_".$i); if($linka==3)$d->b=$this->createLinkTab($d->b,$campo."_".$d->a); $seg[$i]=ceckBox::initBox($field,$ce,$d->b,$d->a); $seg[$i]=$seg[$i]->writeBox(); $i++; } $userTable= new table(0,$col,$seg); $userTable->setStyle(4,0,0,"testo",$id); if(!empty($w))$userTable->setWidth($w); return $userTable->makeTable(); } function getData($query){ $this->Lista=$this->db->get_results($query); return $this->Lista; } function createLink($value,$i){ $html="".$value.""; return $html; } function createLinkTab($value,$i){ $html="".$value.""; return $html; } } db=$db; $this->hideDescrizione=$hideDescrizione; // mosta nascondi descrizioni $this->Id_sub=$Id_sub; } function setCurId($Id){ $this->curId=$Id; } //setto la lingua function setLang($value){ $this->curLang=$value; } // function extra solo quelli non obsoleti function setActive(){ $this->isActive=1; } // soloi pubblicati function setPub(){ $this->isPub=1; } // soloi pubblicati function setReserved(){ $this->isReserved=1; } // setta il dominio corrente function setDomain($domian){ $this->curDomain=$domian; } // soloi pubblicati function setCurField($field){ $this->curField=$field; } function setLimit($i=0,$f=10){ $this->limit= " Limit ".$i.",".$f; } function setTable($tab){ $this->tab.=",".$tab; } function setSelect($sel){ if(ma_not_null($this->sel))$this->sel.=",".$sel; else $this->sel=$sel; } function setOrder($Order){ $this->Order=$Order; } function addJoin($tab){ $this->tab.=" left join ".$tab; } function initWhere($where=''){ $this->wObj=new where; $this->wObj->setWhere($where); } function setGroupBy($groupby){ if(ma_not_null($this->groupBy))$this->groupBy.=",".$groupby; else $this->groupBy=" group by " .$groupby; } // set query function getData($mode=1){ $this->qE="SELECT ".$this->sel." From ".$this->tab." where ".$this->wObj->getWhere()." ".$this->groupBy." Order By ".$this->Order .$this->limit ; if($mode==1)$this->Data=$this->db->get_results($this->qE); else if($mode==2)$this->Data=$this->db->get_row($this->qE); else if($mode==3)$this->Data=$this->db->get_var($this->qE); if($this->debug) echo $this->qE; return $this->Data; } // set query function countRows(){ $this->qC="SELECT count(*) From ".$this->tab." where ".$this->wObj->getWhere()." ".$this->groupBy ; $this->Data=$this->db->get_var($this->qC); if($this->debug) echo $this->qC; return $this->Data; } // this function retur the query function debugQ(){ echo $this->qE."
"; } function updateById($id,$value){ $q="UPDATE ".$this->tab." SET ".$this->curField."= '".addslashes($value)."', lastUser='".ma_getParameter('uid')."' WHERE ".$this->primary_key[0]." = '".$id."'"; $this->db->query($q); } function updateSortList($data){ if($data){ $this->sortStep=($this->sortStep)?$this->sortStep:10; $this->sortNum=$this->sortStep; foreach($data as $d){ $this->updateById($d,$this->sortNum); $this->sortNum=$this->sortNum+$this->sortStep; } } } function removeItem($Id){ echo $this->qD="update ".$this->tablename." set Disable=1, lastUser='".ma_getParameter('uid')."' where ".$this->primary_key[0]."='".$Id."'"; $this->db->query($this->qD); } function deleteItem($Id){ $this->qD="Delete from ".$this->tablename." where ".$this->primary_key[0]."='".$Id."'"; $this->db->query($this->qD); } function deleteItemValue($campo,$Id){ $this->qD="update ".$this->tablename." set ".$campo."='', lastUser='".ma_getParameter('uid')."' where ".$this->primary_key[0]."='".$Id."'"; $this->db->query($this->qD); } function insertItem($field,$values){ $this->qInsert="Insert INTO ".$this->tablename." (".$field.") VALUES(".$values.") "; $this->db->query($this->qInsert); } // basic get data can be override by the extended class function _ma_pre_getData($where=''){ // only do this if sql_select is empty if (empty($this->sel)) { $this->sel = $this->suffix.'.*'; $this->tab= $this->tablename." as " .$this->suffix." "; if(ma_not_null($where))$where=$this->suffix.".".$this->primary_key[0]."='".$where."'"; else $where=1; } // if else $where=1; $this->initWhere($where); } // _cm_pre_getData function getRow($where){ $this->_ma_pre_getData($where); $this->getData(2); $this->getData(2); return $this->Data; } // _cm_pre_getData //************ ritorna velocemente i dati di una riga function ma_getFastRow($Id_sez,$Id=''){ if(ma_not_null($Id)){ $objSez= new $Id_sez; $objSez->getRow($Id); return $objSez->Data; } else return ''; } function getPrimaryKey(){ $datas = $this->db->get_results("SELECT * FROM $this->tab limit 0,1"); // prendo il primo campo della tabella $data=$this->db->get_col_info("name"); return $this->PrimaryKey=$data[0]; } function ckItem($field,$value){ $this->_ma_pre_getData(); $this->initWhere(1); $this->wObj->setEq($field,$value); $this->getData(2); if($this->Data)return true; else return false; } //add this extra function to crete common combo box function makeCombo($Id) { $this->combo=new combo; $this->combo->setInv(); $this->combo->setMode(2); $this->w_cData=$this->combo->makeSimpleCombo($this->Data,$Id); } function _ma_combo_d($Id,$addWhere=1){ $this->tab=$this->tablename ." as ".$this->suffix; $this->sel=$this->sa." as a,".$this->sb." as b"; $this->initWhere($addWhere); if($this->isActive==1)$this->wObj->setEqN("Disable",0); if($this->isPub==1)$this->wObj->setEqN("Pub",1); $this->getData(); //$this->debugQ(); $this->combo=new combo; $this->combo->setInv(); $this->combo->setMode(2); return $this->combo->makeSimpleCombo($this->Data,$Id); } function getCount(){ $this->cField=(ma_not_null($this->cField))?$this->cField:' * '; $this->qC="Select Count(".$this->cField.") from ".$this->tab." where ".str_replace('where','',$this->wObj->getWhere()) ; return $this->NumRows=$this->db->get_var($this->qC); } function initPager($limit=10,$sep='',$stringaPercorso=''){ // setto anche per la ricerca global $cerca; if(!empty($cerca))$this->ricerca($cerca); $p= new Pager; $p->sep=$this->sep; $this->getCount($countF); $this->start = $p->findStart($limit); $p->maxPages = $this->maxPages; $p->useStep=$this->useStep; $this->pages = $p->findPages($this->NumRows, $limit); $this->pagelist =$p->pageList($_REQUEST['page'],$this->pages,$stringaPercorso); $this->setLimit($this->start,$limit); return $this->pagelist; } function ricerca($parola){ $this->parola=$parola; $c= new cerca; $where=$this->wObj->getWhere(); $c->setData( $this->searchField ,$where); $this->wObj->where=$c->getQuery($this->parola); } function pagerString($pathString){ if(ma_not_null($this->pagerString))$this->pagerString.="&".$pathString; else $this->pagerString=$pathString; } //lista semplice function _ma_getList($dominio='',$status=0){ $this->_ma_pre_getData(); $this->tab=$this->tablename." as ".$this->suffix; $this->initWhere($this->suffix.".Disable=0"); if($dominio)$this->wObj->setEq($this->suffix.".Dominio",$dominio); if($this->lang) { $this->tab=$this->tablename." as ".$this->suffix. " left join ".TABLE_CATEGORYTREE_DESCRIZIONI.' as cl on cl.IdOpzioni='.$this->suffix.'.Id'; $this->setSelect('cl.Label as b, cl.IdOpzioni as a'); $this->wObj->setEq('Lingua',$this->lang); } else { if($this->sa)$this->setSelect($this->sa.' as a'); if($this->sb)$this->setSelect($this->sb.' as b'); if($this->sc)$this->setSelect($this->sc.' as c'); $this->tab=$this->tablename." as ".$this->suffix; } } function _ma_getOptions($dominio='',$autoload=false){ $this->_ma_pre_getData(); $this->tab=$this->tablename." as ".$this->suffix; if($this->sa)$this->setSelect($this->sa.' as a'); if($this->sb)$this->setSelect($this->sb.' as b'); if($this->sc)$this->setSelect($this->sc.' as c'); if($autoload===true)$this->wObj->setEq($this->suffix.".FlagAutoLoad",1); if($dominio)$this->wObj->setEq($this->suffix.".IdCategory",$dominio); } function actionHandler($dataList,$value){ if(is_array($dataList)){ foreach($dataList as $d){ if($this->actionType=='update'){ $this->updateById($d,$value); } elseif($this->actionType=='insert'){ } } } else { } } /**************************** some layout helper funtion **********************/ /****************** manage the suggest list ***********************/ function suggestList($value){ $this->_ma_pre_getData(); $this->suggestField=($this->suggestField)?$this->suggestField:$this->sb; $this->initWhere($this->suffix.".Disable=0"); $this->wObj->setLike($this->suggestField,$value); $this->setSelect($this->suggestField.' as a'); //$this->setGroupBy($this->suggestField); $this->getData(); if($this->Data){ $listHTML=ma_helper_list_tag($this->Data); } return $listHTML; } /*********************************** lista tree orizzontale ***********************/ // ritorna l'albero piu il top parent function getTreeFromChild($Id){ if($Id){ $this->arrayTree[]=$Id; // tiene traccia di tutti i parent; $this->_ma_pre_getData(); $this->initWhere($this->suffix.".Id=".$Id); $this->sel=$this->suffix.".IdParent as IdParent"; if($this->sa)$this->setSelect($this->sa ." as a"); if($this->sb && $this->lang=='')$this->setSelect($this->sb ." as b"); if($this->sc)$this->setSelect($this->sc ." as c"); if($this->st)$this->setSelect($this->st ." as t"); //template if($this->getAll)$this->setSelect($this->suffix.".* "); if($this->lang!=''){ $this->tab=$this->tablename." as ".$this->suffix. " left join ".TABLE_CATEGORYTREE_DESCRIZIONI.' as cl on cl.IdOpzioni='.$this->sa; if($this->lang)$this->wObj->setEq('Lingua',$this->lang); if($this->IdTipo)$this->wObj->setEq('IdTipo',$this->IdTipo); $this->setSelect('cl.Label as b'); } $this->getData(2); $this->arrayBreadCrumbs[]=$this->Data ; if(ma_not_null($this->Data->IdParent)){ $this->getTreeFromChild($this->Data->IdParent); } else { $this->arrayRevBreadCrumbs=array_reverse ($this->arrayBreadCrumbs, TRUE); $this->TopId=$Id; return $this->TopId; } } } function getListByCategory($IdCategory,$IdFamily='',$lang='',$IdTipo='Descrizione'){ $this->_ma_pre_getData(); $this->tab=$this->tablename." as ".$this->suffix. " left join ".TABLE_CATEGORYTREE_DESCRIZIONI.' as cl on cl.IdOpzioni='.$this->suffix.'.Id'; $this->setSelect('cl.Label as b, cl.IdOpzioni as a'); $this->initWhere($this->suffix.'.Disable=0'); if($IdCategory)$this->wObj->setEq('IdCategory',$IdCategory); if($IdFamily)$this->wObj->setF_I_S('Dominio',$IdFamily); if($lang)$this->wObj->setEq('Lingua',$lang); if($IdTipo)$this->wObj->setEq('IdTipo',$IdTipo); //$this->wObj->setNotNull('IdParent'); $this->Order=$this->suffix."Title"; } function getRandom($obj,$where='',$lang='',$limit=1) { $objCur=new $obj; $objCur->_ma_pre_getData(); if(ma_not_null($where))$objCur->initWhere($objCur->suffix.'.Disable=0 and '.$where); else $objCur->initWhere($objCur->suffix.'.Disable=0 '); $objCur->Order=" RAND() "; $objCur->limit=" limit ".$limit; $objCur->debug=0; if($limit==1)$objCur->getData(2); else $objCur->getData(); if(ma_not_null($lang) && ma_not_null($objCur->Data->Id)) { $objPageData=new $obj(); $objPageData->setDomain($obj); $objPageData->setLang($lang); $objPageData->getDescrizioni($objCur->Data->Id,'Intro'); $objPageData->getData(2); $objCur->Data->Name=stripslashes($objPageData->Data->b); } return $objCur->Data; } function getlast($obj,$where='',$lang='',$limit=1) { $objCur=new $obj; $objCur->_ma_pre_getData(); if(ma_not_null($where))$objCur->initWhere($objCur->suffix.'.Disable=0 and '.$where); else $objCur->initWhere($objCur->suffix.'.Disable=0 '); $objCur->setSelect(' DATE_FORMAT(DateStart,"%d-%m-%y") as dayStart,DATE_FORMAT(DateStop,"%d-%m-%y") as dayStop'); $objCur->limit=" limit ".$limit; $objCur->Order=" DateStart DESC "; if($limit==1)$objCur->getData(2); else $objCur->getData(); if(ma_not_null($lang) && ma_not_null($objCur->Data->Id)) { $objPageData=new $obj(); $objPageData->setDomain($obj); $objPageData->setLang($lang); $objPageData->getDescrizioni($objCur->Data->Id,'Intro'); $objPageData->getData(2); $objCur->Data->Name=stripslashes($objPageData->Data->b); } return $objCur->Data; } function getDescrizioni($Id,$IdTipo='Name'){ $labelField=' cd.Label '; $this->sel =$this->suffix.'.*,'.$labelField.' as b'; $this->tab= $this->tablename." as " .$this->suffix." "; if($this->curLang){ $this->tab.=" left join ".TABLE_CATEGORYTREE_DESCRIZIONI." cd on ".$this->suffix.".Id=cd.IdOpzioni"; $langWhere=" and Lingua='".$this->curLang."' "; } $this->initWhere($this->suffix.".Id ='".$Id."' ".$langWhere); if($IdTipo)$this->wObj->setEq('cd.IdTipo',$IdTipo); if($this->curDomain)$this->wObj->setEq('cd.IdPage',$this->curDomain); } function lang_text_helper($curPage,$data,$lang){ if($curPage=='page')$objPageLang=new articoli(); else if(class_exists($curPage))$objPageLang=new $curPage(); else $objPageLang=new articoli(); $objPageData=new articoli(); //estraggo tutti i campi in lingua foreach ($objPageLang->fieldspec as $chiave => $valore) { if($valore['lang']==1){ $objPageData->getPageData($data->a,$lang,$chiave,$curPage); $objPageData->debug=0; $objPageData->getData(2); $data->$chiave=stripslashes($objPageData->Data->b); $i++; } } return $data; } function getDescrizioneByLang($Id,$lang,$IdTipo='Name',$Dominio){ $articoli= new articoli(); $articoli->curLang=$lang; $articoli->curDomain=$Dominio; $articoli->getDescrizioni($Id,$IdTipo); $articoli->debug=0; $articoli->getData(2); return stripslashes($articoli->Data->b); } function getChildData($curArticle,$pageTopId,$domain,$nLang='0',$tipo='Name'){ global $lang; $objMenuTree=new treeHTML(); if($nLang>1){ $objMenuTree->setData('article',$domain,$lang,'d.Sort','cd.Label'); } else { $objMenuTree->setData('article',$domain,$lang,'d.Sort','d.Name'); } $objMenuTree->setTipo($tipo); $objMenuTree->_ma_combo_parent($curArticle,$pageTopId,0,' '); return $objMenuTree->arrayDataTree; } function get_first_child($IdParent,$data) { foreach($data as $d){ if($d->IdParent==$IdParent){ $this->dataChild=$d; return $d->a; } } } /*********************** utility***********************/ function indent($level=0){ $str="|"; for ($i=0;$i<$level;$i++){ $str.="___"; } return $str; } function storeQuery(){ $this->listQuery[]=$this->db->last_query; } function errorHandlaer($error){ $this->errorCode=$error; } // daniele 2009.11.18 // generate an unique code function createCode($p_string, $start, $lenght) { $newString = $p_string . substr($p_string,$start,$lenght); return md5($newString); } function pageCodeHandler($mode=''){ $mainTab=ma_getParameter('mainTab'); $pageName=ma_getParameter($mainTab.'_Name'); if(!ma_not_null($_POST[$mainTab.'_pageCode']) || $mode=='up' )$_POST[$mainTab.'_pageCode']=ma_sanitize_seo_page_title($pageName); } function ma_getPageIdByPageCode($Id_sez,$pageCode){ $objSez= new $Id_sez; $objSez->_ma_pre_getData(); $objSez->initWhere($objSez->suffix.".pageCode='".$pageCode."'"); $objSez->getData(2); $objSez->tab=$objSez->tablename; $pk=$objSez->getPrimaryKey(); //$objSez->debugQ(2); return $objSez->Data->$pk; } function generatePassword($length = 8){ // start with a blank password $password = ""; // define possible characters $possible = "0123456789bcdfghjkmnpqrstvwxyz"; // set up a counter $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($password, $char)) { $password .= $char; $i++; } } // done! return $password; } } /*********************************alcuni utility per le date ***************************/ function _ma_combo_year($Id){ $this->tab=$this->tablename." as at"; $this->sel="DATE_FORMAT(DateStart,'%Y') as a, DATE_FORMAT(DateStart,'%Y') as b,count(DATE_FORMAT(DateStart,'%Y')) as n"; $this->initWhere("1"); if(is_array($this->Domain))$this->wObj->setEqArr($this->suffix.'.Dominio',$this->Domain); else if($this->Domain)$this->wObj->setEq('Dominio',$this->Domain); $this->setGroupBy("DATE_FORMAT(DateStart,'%Y')"); $this->Order='a DESC'; $this->debug=0; $this->getData(); $this->combo=new combo; $this->combo->setInv(); $this->combo->setMode(2); return $this->combo->makeSimpleCombo($this->Data,$Id); } function _ma_combo_date($Id,$date='%Y'){ $this->tab=$this->tablename." as at"; $this->sel="DATE_FORMAT(DateStart,$date) as a, DATE_FORMAT(DateStart,$date) as b"; $this->initWhere("1"); $this->initWhere($this->suffix.".Disable=0"); if(is_array($this->Domain))$this->wObj->setEqArr($this->suffix.'.Dominio',$this->Domain); else if($this->Domain)$this->wObj->setEq('Dominio',$this->Domain); $this->setGroupBy("DATE_FORMAT(DateStart,$date)"); $this->Order='a DESC'; $this->getData(); $this->combo=new combo; $this->combo->setInv(); $this->combo->setMode(2); return $this->combo->makeSimpleCombo($this->Data,$Id); } ?>