2, 'portability' => MDB2_PORTABILITY_ALL ); $dsn = array( 'phptype' => DBTYPE, 'username' => DBUSERNAME, 'password' => DBPASSWORD, 'hostspec' => DBHOST, 'database' => DBNAME, ); $db = MDB2::connect($dsn, $options); if (PEAR::isError( $db )) { die("DB connection error"); } $db->setFetchMode(MDB2_FETCHMODE_ASSOC); $db->loadModule('Extended'); define('ROOT', $_SERVER['DOCUMENT_ROOT'] . "/" ); /** * Number of messages saved in the user session * */ define('CONSOLE_MSG_NB', '10'); /** * Data folder * */ define('DATA', 'data/'); define('OPUSDIR', ROOT); define('SITEDOCS', 'docs'); /** * Base language */ define('BASELAN', 'fr'); define('LAN', 'de'); define('PAGINGNB', 50); /** * */ $modules = array( "user" => array("title" => "Users & contact"), "article" => array("title" => "Contenu magazine"), "concours" => array("title" => "Gestion des concours"), "work" => array("title" => "Offres d'emploi"), "pub" => array("title" => "Gestion de la PUB") ); /** * Languages */ $languages = array("fr" => "Français", "de" => "Deutsch", "it" => "Italien");', ' id="' . $genericname . "-" . $row[$id] . '" ' . $altc . '>', $ro); } else { $r .= $ro; } foreach( $row as $cl => $col ){ if( $showid || $col != 'id' ){ if( $class ){ $r .= str_replace('>', ' class="' . $cl . '">', $co); } else{ $r .= $co; } if( $col == '' ){ $r .= ' '; } else { if( $htmlent ){ $r .= Accents2HTML($col ); } else { $r .= $col ; } } $r .= $cc; } } $r .= $rc; if( $alt ){ if( $altc == 'class="odd"' ){ $altc = ''; } else { $altc = 'class="odd"'; } } } return array('data' => $r, 'nb' => count( $data )); } } function displayError( $error ){ echo $error; exit(); } function prepareHtml( $data, $handleFileds = array() ){ if( is_array( $data )){ foreach( $data as $key => $val ){ if( !$handleFields || in_array($key, $handleFields )){ $data[$key] = prepareHtml( $val, $handleFields ); } else { $data[$key] =$val; } } return $data ; } else { return utf8_encode(Accents2HTML( $data ) ); } } function stripTags( $data, $handleFileds = array() ){ if( is_array( $data )){ foreach( $data as $key => $val ){ if( !$handleFields || in_array($key, $handleFields )) $data[$key] = stripTags( $val, $handleFields ); else { $data[$key] = $val; } } return $data ; } else { return strip_tags( $data ); } } function stripMyTags($str, $tags) { if(!is_array($tags)) { $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags)); if(end($tags) == '') array_pop($tags); } foreach($tags as $tag) $str = preg_replace('#]*>#is', '', $str); return $str; } function prepare4Sql( $data ){ if( is_array( $data )){ foreach( $data as $key => $row ){ $data[$key] = prepare4Sql($row); } return $data; } return utf8_decode( $data ); } function Accents2HTML ( $string ){ $chars = array("[À]" => "À", "[Á]" => "Á","[Â]" => "A", "[Ã]" => "A", "[Ä]" => "Ä", "[Å]" => "A", "[Ç]" => "Ç", "[È]" => "È", "[É]" => "É", "[Ê]" => "Ê", "[Ë]" => "E", "[Ì]" => "Ì", "[Í]" => "I", "[Î]" => "I", "[Ï]" => "I", "[Ð]" => "D", "[Ñ]" => "N", "[Ò]" => "Ò", "[Ó]" => "Ó", "[Ô]" => "Ô", "[Õ]" => "O", "[Ö]" => "Ö", "[Ù]" => "Ù", "[Ú]" => "Ú", "[Û]" => "Û", "[Ü]" => "Ü", "[Ý]" => "Y", "[ß]" => "s", "[à]" => "à", "[á]" => "á", "[â]" => "â", "[ã]" => "a", "[ä]" => "ä", "[å]" => "a", "[ç]" => "ç", "[è]" => "è", "[é]" => "é", "[ê]" => "ê", "[ë]" => "ë", "[ì]" => "i", "[í]" => "i", "[î]" => "î", "[ï]" => "ï", "[ð]" => "o", "[ñ]" => "n", "[ò]" => "ò", "[ó]" => "o", "[ô]" => "ô", "[õ]" => "o", "[ö]" => "ö", "[ø]" => "o", "[ù]" => "ù", "[ú]" => "ú", "[û]" => "û", "[ü]" => "ü", "[ý]" => "y", "[ÿ]" => "y", "[€]" => "€" ); if( is_array( $string ) ){ foreach( $string as $key => $val ){ $return[$key] = Accents2HTML($val) ; } return $return; } elseif ( is_object( $string )){ return $string; } else{ return preg_replace( array_keys($chars), array_values($chars), $string ); } } function normalize ($string) { $Caracs = array("¥" => "Y", "µ" => "u", "À" => "A", "Á" => "A", "," => "-", "Â" => "A", "Ã" => "A", "Ä" => "A", "Å" => "A", "Æ" => "A", "Ç" => "C", "È" => "E", "É" => "E", "Ê" => "E", "Ë" => "E", "Ì" => "I", "Í" => "I", "Î" => "I", "Ï" => "I", "Ð" => "D", "Ñ" => "N", "Ò" => "O", "Ó" => "O", "Ô" => "O", "Õ" => "O", "Ö" => "O", "Ø" => "O", "Ù" => "U", "Ú" => "U", "Û" => "U", "Ü" => "U", "Ý" => "Y", "ß" => "s", "à" => "a", "á" => "a", "â" => "a", "ã" => "a", "ä" => "a", "å" => "a", "æ" => "a", "ç" => "c", "è" => "e", "é" => "e", "ê" => "e", "ë" => "e", "ì" => "i", "í" => "i", "î" => "i", "ï" => "i", "ð" => "o", "ñ" => "n", "ò" => "o", "ó" => "o", "ô" => "o", "õ" => "o", "ö" => "o", "ø" => "o", "ù" => "u", "ú" => "u", "û" => "u", "ü" => "u", "ý" => "y", "ÿ" => "y", "|" => "", "$" => "", "_" => "_", "`" => "_", "^" => "" , "~" => "", "\\" => "", "/" => "-", ">" => "", "\"" => "", "?" => "", ":" => "-", "*" => "", "<" => "", "(" => "-", ")" => "-", "+" => "", "=" => "", "#" => "", "@" => "", "¬" => "", "§" => "", "°" => "", ";" => "", ":" => "" ); $string = strtr($string, $Caracs); $string = str_replace('--','-',$string); $string = str_replace('--','-',$string); $string = str_replace('--','-',$string); return strtolower($string); } function setMsg( $msg, $title="", $msgType="show" ){ global $bsMessages; if( !$bsMessages ){ $bsMessages = array() ; } if( is_array( $msg )){ $msg = var_export( $msg, true ); } $msg = array( "type" => $msgType, "title" => $title, "msg" => $msg ); $bsMessages[] = $msg; switch( $msgType ){ case "crash": $fch = fopen($_SERVER['DOCUMENT_ROOT'] . "/bs/logs/crashes.log", "a"); break; case "sql": $fch = fopen($_SERVER['DOCUMENT_ROOT'] . "/bs/logs/sqlerrors.log", "a"); break; } if( $fch ){ $logMsg = date("Y-m-d H:i") . " : " . $msg[0]['title']. "\n"; $logMsg .= "-----------------------------------------------------------------------------------\n"; $logMsg .= str_replace("\t", "", $msg[0]['msg']). "\n\n\n"; fwrite( $fch, $logMsg); fclose( $fch ); } } function is_utf8($string) { // v1.01 define('_is_utf8_split',5000); if (strlen($string) > _is_utf8_split) { // Based on: http://mobile-website.mobi/php-utf8-vs-iso-8859-1-59 for ($i=0,$s=_is_utf8_split,$j=ceil(strlen($string)/_is_utf8_split);$i < $j;$i++,$s+=_is_utf8_split) { if (is_utf8(substr($string,$s,_is_utf8_split))) return true; } return false; } else { // From http://w3.org/International/questions/qa-forms-utf-8.html return preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$%xs', $string); } } function utf8( $data, $type = 'decode'){ if( is_array( $data )){ foreach( $data as $k => $d ){ $data[$k] = utf8( $d, $type ); } return $data; } else { if( $type == 'decode' ){ if( is_utf8( $data ) ) { return utf8_decode( $data ); } else { return $data; } } else { if( !is_utf8 ( $data )){ return utf8_encode( $data ); } else { return $data ; } } } } function getExtention( $file ){ $temp = explode(".", $file ); return strtolower( array_pop( $temp ) ); }db = $db; $this->prefix = PREFIX; if( !$this->tableRef ){ $this->tableRef = $this->prefix . get_class( $this ); } $this->defaultfields = $this->tableRef . ".*"; $this->model = get_class($this); $this->primary = array('id','language'); $this->tableTranslation[$this->tableRef] = $this->tableRef; $this->notTranslatedFields = array(); $this->files = array(); } public function getTags( $language = "fr") { $res = array(); $rows = $this->db->getAll("SELECT tag FROM " . $this->prefix . "tag WHERE language='" . $language . "' ORDER BY tag"); foreach( $rows as $row ){ $res[] = $row['tag']; } return $res; } public function getMyTags( $id, $language='fr', $status=0 ) { $res = array(); $rows = $this->db->getAll("SELECT tag.id, tag.tag, ind.main main FROM " . $this->prefix . "tag tag INNER JOIN " . $this->prefix . "tagdistribution ind ON ind.tag = tag.id WHERE ind.content_type='" . $this->model . "' AND ind.referer=$id AND tag.language='$language' ORDER BY tag.tag"); foreach( $rows as $row ){ if( $status ){ if( $row['main'] ){ $main = "!"; } else { $main = ""; } $res[$row['id']] = $row['tag'] . $main ; } else { $res[$row['id']] = $row['tag']; } } return $res; } public function getMyTags4Admin( $id, $language='fr', $status=0 ) { $res = array(); $rows = $this->db->getAll("SELECT tag.id, tag.tag, ind.main main , tag.language language FROM " . $this->prefix . "tag tag INNER JOIN " . $this->prefix . "tagdistribution ind ON ind.tag = tag.id WHERE ind.content_type='" . $this->model . "' AND ind.referer=$id ORDER BY tag.tag"); foreach( $rows as $row ){ if( $res[$row['id']]['language'] != $language ){ $res[$row['id']] = array("language" => $row['language'], "tag" => $row['tag']); } } return $res; } public function setTags( $id, $tags ){ //print_r( $tags ); exit(); $ex = array(); if( $tags && is_array( $tags ) ){ foreach( $tags as $t ){ $row = $this->db->getRow("SELECT id FROM " . $this->prefix . "tagdistribution WHERE content_type='" . $this->model . "' AND tag=$t AND referer=?", array("text"), array( $id )); //echo "SELECT id FROM " . $this->prefix . "tagdistribution WHERE content_type='" . $this->model . "' AND tag=$t AND referer=$id"; if( $row ){ $ex[] = $row['id']; $this->db->query("INSERT INTO " . $this->prefix . "tagdistribution( id,tag,content_type,referer,main) VALUES(".$row['id'].",'$t','" . $this->model ."', $id, '0')" ) ; } else { $row = $this->db->getRow("SELECT IFNULL(MAX(id)+1,1) id FROM " . $this->prefix . "tagdistribution"); $newid = $row['id']; $ex[] = $row['id']; $this->db->query("INSERT INTO " . $this->prefix . "tagdistribution( id,tag,content_type,referer,main) VALUES($newid,'$t','" . $this->model ."', $id, '0')" ) ; } } } if( !$ex ){ $this->db->query("DELETE FROM " . $this->prefix . "tagdistribution WHERE referer=" . $id . " AND content_type='" . $this->model . "'"); } else { $this->db->query("DELETE FROM " . $this->prefix . "tagdistribution WHERE referer=" . $id . " AND content_type='" . $this->model . "' AND id NOT IN(" . implode(",", $ex) . ")"); } } /* public function setTags( $id, $language, $tags ){ $temp = explode(",", $tags ); $ex = array(); foreach( $temp as $t ){ if( $t ){ if(substr( $t, strlen($t)-1,1 ) == "!" ){ $t = substr( $t, 0, strlen($t)-1 ); $main = '1'; } else{ $main = '0'; } $t = utf8_decode($t); $row = $this->db->getRow("SELECT id from " . $this->prefix . "tag WHERE tag=? AND language=?", array("text","text"), array($t, $language)); if( !$row['id'] ){ $row = $this->db->getRow("SELECT IFNULL(MAX(id)+1,1) id FROM " . $this->prefix . "tag"); $tagid = $row['id']; $this->db->query("INSERT INTO " . $this->prefix . "tag(id,language,tag) VALUES($tagid,'$language','$t')" ) ; } else { $tagid = $row['id']; } $row = $this->db->getRow("SELECT id FROM " . $this->prefix . "tagdistribution WHERE content_type='" . $this->model . "' AND tag=$tagid AND language=? AND referer=?", array("text","text"), array( $language, $id )); if( $row ){ $ex[] = $row['id']; $this->db->query("UPDATE " . $this->prefix . "tagdistribution SET main='$main' WHERE id=" . $row['id']); ; } else { $row = $this->db->getRow("SELECT IFNULL(MAX(id)+1,1) id FROM " . $this->prefix . "tagdistribution"); $newid = $row['id']; $ex[] = $row['id']; $this->db->query("INSERT INTO " . $this->prefix . "tagdistribution(id,language,tag,content_type,referer,main) VALUES($newid,'$language','$tagid','" . $this->model ."',$id,$main)" ) ; } } } $this->db->query("DELETE FROM " . $this->prefix . "tagdistribution WHERE referer=" . $id . " AND content_type='" . $this->model . "' AND id NOT IN(" . implode(",", $ex) . ")"); } */ public function filterBy( $array, $value = "fr" , $key = 'language'){ if(is_array( $array)) { foreach($array as $item) { if($item[$key] == $value) { $temp[] = $item; } } return $temp; } } public function setPrefix( $prefix ){ $this->prefix = $prefix; $this->tableRef = $prefix . get_class( $this ); $this->defaultfields = $this->tableRef . ".*"; } function findByRef( $value, $key = "id" ){ if( $params['joins'] ){ $this->joins = $params['joins']; } if( $params['fields'] ){ $this->fields = $params['fields']; } $joins = $this->prepareJoins(); $fields = $this->prepareFields(); $row = $this->db->getRow(" SELECT " . $fields . " FROM `" . $this->tableRef . "`" . $joins . " WHERE `" . $this->tableRef . "`.`" . $key . "` = ?", array('text'), array( $value )); return $row ; } function findBy2Ref( $value, $key = "id", $value2 = "fr", $key2 = "language" ){ if( $params['joins'] ){ $this->joins = $params['joins']; } if( $params['fields'] ){ $this->fields = $params['fields']; } $joins = $this->prepareJoins(); $fields = $this->prepareFields(); $row = $this->db->getRow(" SELECT " . $fields . " FROM `" . $this->tableRef . "`" . $joins . " WHERE `" . $this->tableRef . "`.`" . $key . "` = ? AND `" . $this->tableRef . "`.`" . $key2 . "` = ?", array('text', 'text'), array( $value, $value2 )); return $row ; } function findByRefs( $array ){ if( $params['joins'] ){ $this->joins = $params['joins']; } if( $params['fields'] ){ $this->fields = $params['fields']; } $joins = $this->prepareJoins(); $fields = $this->prepareFields(); foreach( $array as $key => $value) { $keys .= " AND `" . $this->tableRef . "`.`" . $key . "` = ?"; } $values = implode(',',array_values($array)); $count = count( $array); $type = "text"; for($i = 1 ; $i < $count ; $i++ ) { $type .= ",text"; } $row = $this->db->getRow(" SELECT " . $fields . " FROM `" . $this->tableRef . "` " . $joins . " WHERE 1 = 1 " . $keys, array($type), array( $values )); } public function isOperator( $value ){ if( strtolower($value) == "or" || strtolower( $value ) == "and" || strtolower( $value ) == "between" || strtolower( $value ) == "not" ){ return true; } else { return false; } } function prepareConditions( $conditions = "", $operator="AND", $tab = "" ){ if( !$conditions ){ $conditions = $this->conditions; } if( !$conditions ){ return; } $condsA = Array(); $prefix = PREFIX; foreach( $conditions as $key => $value ){ if( $this->isOperator( $key ) ){ $condsA[] = " (" . $this->prepareConditions( $value, strtoupper( $key ), $tab . "\t") . ") "; } else { $temp = explode(" ", $key); if( count( $temp ) == 1){ $temp1 = explode(".", $temp[0] ); if( count ($temp1) > 1 ){ $k = "`" . $temp1[0] . "`.`" . $temp1[1] . "`"; } else{ $k = "`" . $this->tableRef . "`.`" . $temp1[0] . "`"; } if( is_array( $value )){ $values = implode(",", $value); $condsA[] = "$k = '($values)'"; } else { $condsA[] = "$k = '" . addslashes($value) . "'"; } } else { $temp1 = explode(".", $temp[0] ); if( count ($temp1) > 1 ){ $k = "`" . $temp1[0] . "`.`" . $temp1[1] . "`"; } else{ $k = "`" . $this->tableRef . "`.`" . $temp1[0] . "`"; } if( is_array( $value ) ){ $values = implode(",", $value); $condsA[] = "$k " . $temp[1] . " " . $temp[2] . " ($values)"; } else{ $condsA[] = "$k " . $temp[1] . " " . $temp[2] . " '$value'"; } } } } $condsS = implode( "\n$tab" . "$operator ", $condsA ); if( $condsS ) return ' AND ' . $condsS; } private function prepareJoins( ){ if( !$this->joins ){ return; } foreach( $this->joins as $join ){ $temp = ""; $model = $join[0]; if ( class_exists($model) ){ $mdl = new $model; $tableRef = $mdl->tableRef; } else { $tableRef = PREFIX . $model; } $pre = $join[3]; $alias = $join[3]; $temp = $join[1] . " JOIN " . $tableRef . " $alias ON ("; $n = 0; foreach( $join[2] as $k => $v ){ if( $n > 0 ){ $temp .= " AND "; } $temp1 = explode( " ", $k ); if( count($temp1) == 1 ){ $op = '='; } else { $k = $temp1[0]; $op = $temp1[1]; } $temp2 = explode( ".", $k ); if( substr($v, 0,1 ) == "'" && substr( $v,strlen($v)-1,1) == "'" ){ if( count( $temp2 ) == 1){ $temp .= $this->tableRef . "." . $k . " $op $v"; } else{ $temp .= $k . " $op $v"; } } else { if( count( $temp2 ) == 1){ $temp .= $this->tableRef . "." . $k . " $op " . " $pre." . $v; } else{ $temp .= $k . " $op " . " $pre." . $v; } } $n ++; } $temp .= ")"; $result[] .= $temp; $this->defaultfields .= ",$pre.*"; } return implode( "\n", $result ); } private function prepareGroups( ){ if( !$this->groups ) return; $result .= "GROUP BY "; foreach( $this->groups as $group ){ $temp = explode(".", $group); if( count( $temp ) > 1 ){ $res[] = $temp[0] . "." . $temp[1]; } else{ $res[] = $this->tableRef . "." . $temp[0]; } } return $result . implode(",", $res ); } private function prepareFields(){ if( $this->distinct ){ $dist = "distinct "; } if( !$this->fields ){ return $dist . $this->defaultfields; } foreach( $this->fields as $alias => $field ){ $temp = explode( ".", $field ); if( count( $temp ) > 1){ $res[] .= $temp[0] . "." . $temp[1] . " `$alias`"; } else{ $res[] .= "`" . $this->tableRef . "`.`" . $temp[0] . "` `$alias`"; } } return $dist . implode(", ", $res ); } private function prepareOrders(){ if( !$this->orders ){ return ; } $result = " ORDER BY "; foreach( $this->orders as $f => $s ){ $temp = explode( ".", $f ); if( count( $temp ) > 1){ $res[] .= "`" . $temp[0] . "`.`" . $temp[1] . "` $s"; } else{ $res[] .= "`" . $this->tableRef . "`.`" . $temp[0] . "` $s"; } } return $result . implode(", ", $res ) ; } private function prepareSearch( $keywords, $type='words' ){ if( !$this->searchFields ){ setMsg("sql", "searchFields not defined for model " . $this->model); return; } if( $type == 'words' ){ $temp = array(); $i=1; foreach( $this->searchFields as $sField => $rel ){ if( $rel > 0 ){ $temp[] .= "MATCH (`" . $this->tableRef . "`.`" . $sField . "`) AGAINST ('" . $keywords . "') AS srel" . $i ; $temp1[] = "`" . $this->tableRef . "`.`" . $sField . "`"; $temp2[] = "(srel" . $i . "*" . $rel . ")"; } else { $atemp[] .= "`" . $this->tableRef . "`.`" . $sField . "` = '" . $keywords . "'" ; } $i++; } $result['fields'] = ", " . implode( ",", $temp ); if( $temp && $atemp){ $result['conds'] = "AND (MATCH (" . implode( ",", $temp1 ). ") AGAINST ('" . $keywords . "') OR " . implode(" AND ", $atemp ) . ")"; } elseif( $temp){ $result['conds'] = "AND MATCH (" . implode( ",", $temp1 ). ") AGAINST ('" . $keywords . "')"; } else{ $result['conds'] = "AND " . implode(" AND ", $atemp ) ; } $result['orders'] = "ORDER BY " . implode("+", $temp2) . " DESC"; } else { $temp = array(); foreach( $this->searchFields as $sField => $rel ){ $temp[] = "`" . $this->tableRef . "`.`" . $sField . "` LIKE '%" . $keywords . "%' "; } $result['conds'] = "AND ( " . implode(" OR ", $temp ) . ") " ; } return $result; } private function setLimit($nb, $page ){ if( !$nb ) return; if( !$page ){ $page = 0; } else { $page = $page-1; } $start = $nb * $page ; return "\nLIMIT $start, $nb"; } function getFields( $params ) { if( !$params['formated'] ){ return array_keys($this->fields); } else { $d = array(); foreach( array_keys($this->fields) as $key ){ $d[0][$key] = $key; } return formatData( $d, $params['formated']['tags'], $params['formated']['id'], $this->model, $params['formated']['class'], $params['formated']['alt'] ); } } /** * Enter description here... * * @param string(all,count,first,list,neighbors) $type * @param unknown_type $params */ function find( $type = 'all', $params = array() ){ if( !$params['searchType']){ $params['searchType'] = 'words'; } if( !$params['page']){ if( $params['keepPage'] ){ $params['page'] = $_SESSION['page'][md5($this->model . serialize($params['conditions']))]; } } else { $_SESSION['page'][md5($this->model . serialize($params['conditions']))] = $params['page']; } if( $params['conditions'] ){ $this->conditions = $params['conditions']; } if( $params['joins'] ){ $this->joins = $params['joins']; } if( isset($params['groups']) ){ $this->groups = $params['groups']; } if( $params['orders'] ){ $this->orders = $params['orders']; } if( $params['fields'] ){ $this->fields = $params['fields']; } if( $params['searchFields'] ){ $this->searchFields = $params['searchFields']; } if( $params['distinct'] ){ $this->distinct = true; } $conds = $this->prepareConditions(); $joins = $this->prepareJoins(); $groups = $this->prepareGroups(); $fields = $this->prepareFields(); $orders = $this->prepareOrders(); if( $params['searchKeywords']){ $search = $this->prepareSearch( $params['searchKeywords'], $params['searchType'] ); $orders = $search['orders']; } if( $type == 'letters' ){ $f = array_pop($params['fields']); $f = " UPPER(SUBSTRING($f,1,1)) "; $sql = "SELECT DISTINCT $f letter FROM `" . $this->tableRef . "`\n" . $joins . " WHERE 1=1 " . "\n" . $conds . "\n" . $search['conds'] . "\n" . $groups . "\n ORDER BY $f"; $this->currentQuery = $sql; // echo $sql; //setMsg($sql); $rows = $this->db->getAll( $sql ); if( PEAR::isError( $rows )){ setMsg($sql, "sql", "bad query in model.inc.php -> find" ); } foreach($rows as $row){ $temp[$row['letter']] = true; } for ($c=65; $c <= 90; $c++){ $ch = ($lower) ? strtolower(chr($c)) : chr($c); if( !$temp[$ch] ){ $letters[$ch] = false; } else { $letters[$ch] = true; } } for( $i=0;$i<10;$i++){ if( !$temp[$i] ){ $letters[$i] = false; } else { $letters[$ch] = true; } } return $letters ; } if( $type == 'all' || $type == 'ass'){ $sql = "SELECT SQL_CALC_FOUND_ROWS " . $fields . " " . $search['fields'] . " FROM `" . $this->tableRef . "`\n" . $joins . " WHERE 1=1 " . "\n" . $conds . "\n" . $search['conds'] . "\n" . $groups . "\n" . $orders . "\n" . $this->setLimit( $params['limit'], $params['page']); $this->currentQuery = $sql; //echo $sql; //setMsg($sql); $rows = $this->db->getAll( $sql ); if( PEAR::isError( $rows )){ setMsg($sql, "sql", "bad query in model.inc.php -> find" ); } //echo $sql; /** * get paging */ if( $params['limit'] ){ $sql = "SELECT FOUND_ROWS() nb" ; $row = $this->db->getRow( $sql ); $nb = $row['nb']; $this->paging['nb'] = ceil( $nb / $params['limit'] ); if( $params['page']){ $p = $params['page']; } else { $p = 1; } $temp = $_GET; $qstr = ""; unset( $temp['url'],$temp['language']); foreach( $temp as $k => $v ){ $qstr .= "$k=$v&"; } $this->paging['current'] = $p ; $this->paging['previous'] = $p-1 ; if( $this->paging['previous'] < 1 ){ $this->paging['previous'] = ""; } else { $temp = $p-1; $this->paging['previousurl'] = "?" . $qstr . "page=$temp"; } $this->paging['next'] = $p+1 ; if( $this->paging['next'] > $this->paging['nb'] ){ $this->paging['next'] = ""; } else { $temp = $p+1; $this->paging['nexturl'] = "?" . $qstr . "page=$temp"; } for( $i=0; $i< $this->paging['nb']; $i++ ){ $p = $i + 1; if( $p < 4 ){ $d = "f"; } elseif( $p >= $this->paging['nb'] - 2 ) { $d = "e"; } elseif( $p == $this->paging['current'] || $p == $this->paging['current']-1 || $p == $this->paging['current'] + 1 ) { $d = "e"; } else{ $d = "h"; } $this->paging['pages'][$p] = array("url" => "?" . $qstr . "page=$p", "display" => $d ); } } if( $type == 'ass'){ if( $params['empty']){ $res[] = $params['empty']; } foreach( $rows as $row ){ $res[$row[$params['key']]] = $row[$params['value']]; } return $res; } if( $params['multilanguages'] && $rows ){ foreach( $rows as $row ){ $in[] = $row['id']; } foreach( $params['multilanguages']['languages'] as $k => $f ){ $langs[] = "'$f'"; } $ls = $this->db->getAll( "SELECT id, " . implode(',', $params['multilanguages']['fields'] ) . ", language FROM " . $this->tableRef . " WHERE id IN (" . implode(',', $in) . ") AND language IN(" . implode(',', $langs ) . ")" ); foreach( $ls as $l){ $comp[$l['id']][$l['language']] = $l; } foreach( $rows as $k => $row ){ foreach( $params['multilanguages']['languages'] as $lang ){ if( $comp[$row['id']][$lang]) { foreach( $params['multilanguages']['fields'] as $field ){ $rows[$k][$field . "-" . $lang] = $comp[$row['id']][$lang][$field]; } } } } } return formatData($rows, $params['formated']['tags'], $params['formated']['id'], $this->model, $params['formated']['class'], $params['formated']['alt']); } elseif( $type == 'count' ){ $sql = "SELECT SQL_CALC_FOUND_ROWS " . $fields . " " . $search['fields'] . " FROM `" . $this->tableRef . "`\n" . $joins . " WHERE 1=1 " . "\n" . $conds . "\n" . $search['conds'] . "\n" . $groups . "\n" . $orders . " LIMIT 0,1"; $this->currentQuery = $sql; $rows = $this->db->getAll( $sql ); if( PEAR::isError( $rows )){ setMsg($sql, "sql", "bad query in model.inc.php -> find" ); } $sql = "SELECT FOUND_ROWS() nb" ; $row = $this->db->getRow( $sql ); return $row['nb']; } } public function getPaging(){ if( $this->paging ) return $this->paging; } public function prepareModels(){ $ctrl = array(); $d = dir( $_SERVER['DOCUMENT_ROOT'] . "/bs/models"); while (false !== ($entry = $d->read())) { if( !is_dir($_SERVER['DOCUMENT_ROOT'] . "/bs/models/" . $entry) && $entry != ".." && $entry != "." && $entry != "model.inc.php"){ require_once( $_SERVER['DOCUMENT_ROOT'] . "/bs/models/" . $entry ); $ctrl[$entry] = 1; } } $d->close(); $d = dir( OPUSDIR . "/opus/models"); while (false !== ($entry = $d->read())) { if( !is_dir( OPUSDIR . "/opus/models/" . $entry) && $entry != ".." && $entry != "." && $entry != "model.inc.php"){ if( !$ctrl[$entry] ){ require_once( OPUSDIR . "/opus/models/" . $entry ); } } } $d->close(); } public function update( $data ){ foreach( $data as $k => $v){ // $data[$k] = html_entity_decode($v); } $basicData = $data; foreach( $this->files as $key => $file){ if( $data[$key] && is_file( ROOT . DATA . $data[$key]['src'] ) ){ if( $file['size'] ) { $dims = explode("x", $file['size'] ); if( $dims[0] ){ $mX = $dims[0]; } if( $dims[1] ){ $mY = $dims[1]; } } $oriSizes = getimagesize( ( ROOT . DATA . $data[$key]['src']) ); $imgRoot = ROOT . DATA . $data[$key]['src']; $oX = $oriSizes[0]; $oY = $oriSizes[1]; if( ($mX > $oX || !$mX) && ($mY > $oY || !$mY) ){ copy( ROOT . DATA . $data[$key]['src'], ROOT . DATA . $file['src'] . $data[$key]['name'] ) ; unlink( ROOT . DATA . $data[$key]['src'] ); } else { /** * resize image */ if( $oX > $mX && $mX){ $coef = $mX / $oX; $oX = $mX; $oY = floor( $coef * $oY); } if( $oY > $mY && $mY){ $coef = $mY / $oY; $oY = $mY; $oX = floor( $coef * $oX); } $ext = getExtention( $data[$key]['src'] ); switch( $ext ){ case 'png': $save = imagecreatefrompng( $imgRoot ); $iOut = imagecreatetruecolor( $oX,$oY ) ; imageantialias ( $iOut , true ); imagecopyresampled( $iOut, $save, 0,0,0,0, $oX, $oY, $oriSizes[0], $oriSizes[1] ); $white = imageColorTransparent($iOut); imagepng($iOut, ROOT . DATA . $file['src'] . $data[$key]['name']); break; case 'gif': $save = imagecreatefromgif( $imgRoot ); $iOut = imagecreatetruecolor( $oX,$oY ) ; imagecopyresampled( $iOut, $save, 0,0,0,0, $oX, $oY, $oriSizes[0], $oriSizes[1] ); imagegif($iOut, ROOT . DATA . $file['src'] . $data[$key]['name']); break; case 'jpg': $save = imagecreatefromjpeg( $imgRoot ); $iOut = imagecreatetruecolor( $oX,$oY ) ; $white = ImageColorAllocate ($iOut, 255, 255, 255); imagecopyresampled( $iOut, $save, 0,0,0,0, $oX, $oY, $oriSizes[0], $oriSizes[1] ); imagejpeg($iOut, ROOT . DATA . $file['src'] . $data[$key]['name'],'100'); break; } chmod (ROOT . DATA . $file['src'] . $data[$key]['name'], 0777); } $data[$key] = $file['src'] . $data[$key]['name']; } } if( $this->globalTags ) { $tags = $data['tags']; unset( $data['tags'] ); } if( $data['id'] ){ foreach( $this->primary as $key ){ if( $key != 'language'){ $temp1[] = "$key = ?"; $selectorTypeS[] = "text"; $selectorDataS[] = $data[$key]; } $temp[] = "$key = ?"; $selectorType[] = "text"; $return[$key] = $data[$key]; $selectorData[] = $data[$key]; unset( $data[$key] ); } $selector = "WHERE " . implode(" AND ", $temp ); $selectorS = "WHERE " . implode(" AND ", $temp1 ); $mode = "update"; } else{ $row = $this->db->getRow("SELECT IFNULL(MAX(id)+1,1) id FROM $this->tableRef"); $newid = $row['id']; unset( $data['id'] ); } foreach( $data as $key => $value ){ if( $mode == "update" ){ if( in_array( $key, $this->notTranslatedFields ) ){ $sqlAS[] = "`$key` = ?"; $sqlDS[] = $value; $typesS[] = "text"; } else{ $sqlA[] = "`$key` = ?"; $sqlD[] = $value; $types[] = "text"; } } else { $sqlA[] = "`$key`"; $sqlDA[] = "?"; $types[] = "text"; } } if( $mode == "update"){ if( !$sqlA && !$sqlAS ){ return $basicData; } /** * translated fields */ if( $sqlA ){ $sql = "UPDATE " . $this->tableRef . " SET " . implode(",", $sqlA) . " " . $selector; $nData = array(); foreach( $sqlD as $d){ $nData[] = utf8_decode( $d ); } foreach( $selectorData as $d){ $nData[] = utf8_decode($d); } foreach( $selectorType as $type ){ $types[] = $type; } $sth = $this->db->prepare($sql, $types); if( PEAR::isError( $sth ) ){ setMsg( $sql ); } else { $res = $sth->Execute( $nData ); } if( PEAR::isError( $res ) ){ setMsg( $sql ); } } /** * not translated fields */ if( $sqlAS ){ $sql = "UPDATE " . $this->tableRef . " SET " . implode(",", $sqlAS) . " " . $selectorS; $nData = array(); foreach( $sqlDS as $d){ $nData[] = utf8_decode( $d ); } foreach( $selectorDataS as $d){ $nData[] = utf8_decode($d); } foreach( $selectorTypeS as $type ){ $types[] = $type; } $sth = $this->db->prepare($sql, $types); if( PEAR::isError( $sth ) ){ setMsg( $sql ); } else { $res = $sth->Execute( $nData ); } if( PEAR::isError( $res ) ){ setMsg( $sql ); } } foreach( $return as $key => $value ){ $data[$key] = $value; } } else { $sql = "INSERT INTO `" . $this->tableRef . "`(id," . implode(",", $sqlA) . ") VALUES ($newid," . implode(",", $sqlDA) . ") "; foreach( $data as $d){ $nData[] = utf8_decode($d); } $types = $types ; $this->currentQuery = $sql; $this->currentQueryData = $nData; $this->currentQueryTypes = $types; $sth = $this->db->prepare($sql, $types); $res = $sth->Execute( $nData ) ; if( PEAR::isError( $res ) ){ setMsg( $res ); } $data['id'] = $newid; } /** * handle tags */ if( $this->globalTags ) { $this->setTags( $data['id'], $tags ); } return $data; } public function prepare( $data, $language="", $status='temp', $date_creation = false ){ unset( $data['status'] ); $row = $this->db->getRow("SELECT * FROM `" . $this->tableRef . "` WHERE id=? AND language=?", array('text','integer'), array( $data['id'], $language) ); if( !$row ){ if( !$data ){ $row = $this->db->getRow("SELECT IFNULL(MAX(id)+1,1) id FROM $this->tableRef"); $data['id'] = $row['id']; if( in_array("language", $this->primary ) ){ if( $date_creation ) { $sql = "INSERT INTO `" . $this->tableRef . "`(id,language,status,date_creation) VALUES(?,?,?,?)"; $sth = $this->db->prepare($sql, array("integer","text", "text","date")); $sth->execute(array($data['id'], $language, $status, date("Y-m-d H:i:s") )); } else { $sql = "INSERT INTO `" . $this->tableRef . "`(id,language,status) VALUES(?,?,?)"; $sth = $this->db->prepare($sql, array("integer","text", "text")); $sth->execute(array($data['id'], $language, $status )); } } else { $sql = "INSERT INTO `" . $this->tableRef . "`(id,status) VALUES(?,?)"; $sth = $this->db->prepare($sql, array("integer", "text")); $sth->execute(array($data['id'], $status )); } } else { if( in_array("language", $this->primary ) ){ $sql = "INSERT INTO `" . $this->tableRef . "`(id,language,status) VALUES(?,?,?)"; $sth = $this->db->prepare($sql, array("integer", "text", "text")); $sth->execute(array($data['id'], $language, $status )); } else { $sql = "INSERT INTO `" . $this->tableRef . "`(id,status) VALUES(?,?)"; $sth = $this->db->prepare($sql, array("integer", "text")); $sth->execute(array($data['id'], $status )); } } } foreach( $data as $key => $value ){ if( is_numeric( $value ) || ( $this->notTranslatedFields && in_array($key, $this->notTranslatedFields ) ) ){ $pData[$key] = $value; } $pData['language'] = $language; } if( $this->globalTags ) { $pData['tags'] = $data['tags']; } return $this->update( $pData ); } public function update1( $data ){ if( isset($data['id']) && isset($data['language'])){ if( $data['id'] ){ $selector = "WHERE id=? AND `language`=?"; $selectorData = array( $data['id'], $data['language'] ); $selectorType = array( "id" => "int", "language" => "text" ); $id = $data['id']; $lan = $data['language']; unset( $data['language'],$data['id']); $mode = "update"; } else{ $row = $this->db->getRow("SELECT IFNULL(MAX(id)+1,1) id FROM $this->tableRef"); $newid = $row['id']; unset( $data['id'] ); } foreach( $data as $key => $value ){ if( $mode == "update" ){ $sqlA[] = "`$key` = ?"; $types[] = "text"; } else { $sqlA[] = "`$key`"; $sqlDA[] = "?"; $types[] = "text"; } } if( $mode == "update"){ $sql = "UPDATE " . $this->tableRef . " SET " . implode(",", $sqlA) . " " . $selector; $ndata = $data + $selectorData; foreach( $ndata as $d){ $nData[] = utf8_decode($d); } $types = $types + $selectorType; echo $sql; $sth = $this->db->prepare($sql, $types); $res = $sth->Execute( $nData ); if( PEAR::isError( $res ) ){ setMsg( $res ); } $data['id'] = $id; $data['language'] = $lan; } else { $sql = "INSERT INTO `" . $this->tableRef . "`(id," . implode(",", $sqlA) . ") VALUES ($newid," . implode(",", $sqlDA) . ") "; foreach( $data as $d){ $nData[] = utf8_decode($d); } $types = $types ; $sth = $this->db->prepare($sql, $types); $res = $sth->Execute( $nData ) ; if( PEAR::isError( $res ) ){ setMsg( $res ); } $data['id'] = $newid; } } return $data; } public function delete( $value, $key = "id" ){ if( is_array( $value )){ foreach( $value as $v ){ $this->delete( $v, $key ); } return; } $sql = "DELETE FROM `" . $this->tableRef . "` WHERE `$key` = ?"; $sth = $this->db->prepare( $sql ) ; $sth->Execute( array( $value ) ); } public function checkForm( $data, $file ) { $mailCont = @file_get_contents( $file ); $pattern = "|\<[^\>]*name=\"form\[([^\"]*)]\"[^\>]*class=\"[^\>]*required[^\>]*\"[^\>]*\>|i"; preg_match_all($pattern, $mailCont,$temp); $req = ( $temp[1] ); $pattern = "|\<[^\>]*name=\"form\[([^\"]*)]\"[^\>]*class=\"[^\>]*email[^\>]*\"[^\>]*\>|i"; preg_match_all($pattern, $mailCont,$temp); $emails = ( $temp[1] ); $return['sent'] = '1'; foreach( $req as $f ){ if( !$data[$f]){ $return['sent'] = ''; $return['msg'] = 'please fill all required fields.
'; } } foreach( $emails as $f ){ if( !$data[$f]){ $return['sent'] = ''; $return['msg'] .= 'Please check email format.
'; } } if( !$return['sent'] ){ return $return; } } }
Fatal error: Uncaught Error: Undefined constant "OPUSDIR" in /var/www/clients/client1/web255/web/opus/views/view.inc.php:3 Stack trace: #0 /var/www/clients/client1/web255/web/index.php(18): require_once() #1 {main} thrown in /var/www/clients/client1/web255/web/opus/views/view.inc.php on line 3