function insert($table, $val, $aux_table)
{
$valori_extra = $val;
$db = new DB_Sql;
$dbw = new DB_Sql;
global $campuri_data;
$q = "select * from ".PREFIX_TABLE.$table."";
$result_u = $db->query($q);
$numar = $db->num_fields();
for ($i = 0; $i <= $numar-1; $i++) {
$finfo[] = $result_u->fetch_field_direct($i);
}
foreach($finfo as $ff){
if($ff->name != $table."_id") {
$nume_camp[] = $ff->name;
$nume_c[] = $ff->name;
}
}
if($val['gmapLat'] !=""){
$adrese = getAddressFromLatLng($val['gmapLat'], $val['gmapLng']);
$val['adresa'] = $adrese['adresa'];
$val['adresa_exacta'] = $adrese['adresa_exacta'];
$val['adresa_curata'] = $adrese['adresa_curata'];
}
//print_p($val);die;
$q_insert = "INSERT INTO ".PREFIX_TABLE.$table." (";
settype($val,"array");
if(!is_array($val))
{
return false;
}
foreach ($nume_camp as $camp)
{
if(!empty($camp) && $camp!= $table.'_id')
{
if($valoare_post == "imagini_actuale")
{
!$string1 or $string1 .= ", ";
$string1.= "`imagini`";
}
elseif($valoare_post == "related_old")
{
!$string1 or $string1 .= ", ";
$string1.= "`related`";
}
else
{
!$string1 or $string1 .= ", ";
$string1.= "`".$camp."`";
}
}
}
$q_insert .= $string1;
$q_insert .= ") VALUES (";
foreach ($nume_c as $valoare_post)
{
//echo $valoare_post."
";
if($valoare_post!= $table.'_id')
{
if(in_array($valoare_post, $campuri_data)){
$timestamp = strtotime($val[$valoare_post]);
$val[$valoare_post] = date("Y-m-d H:i:s", $timestamp);
//!$string or $string .= " ";
$string .= "";
}
if($valoare_post == "parola")
{
!$string or $string .= ", ";
$string.= '\''.MD5($val[$valoare_post]).'\'';
}
elseif($valoare_post == 'pay_date')
{
!$string or $string .= ", ";
$string .= '\''.transformDateMysqlRom($_POST['pay_date']).'\'';
}
// elseif($valoare_post == "data")
// {
// !$string or $string .= ", ";
// $string.= 'NOW()';
// }
elseif($valoare_post == "adaugat_de")
{
!$string or $string .= ", ";
$string.= $_SESSION['SESS_id'];
}
else
{
if (is_array($val[$valoare_post])) {
foreach ($val[$valoare_post] as $final_de_inserat)
if($val[$valoare_post]!="Array") {
$val[$valoare_post].= $final_de_inserat . "|||";
}
}
else {
if($val[$valoare_post]!="Array") {
$val[$valoare_post] = $val[$valoare_post];
}
}
if (strpos($val[$valoare_post], 'Array') !== false) {
$valoare_post_ex = explode("Array",$val[$valoare_post]);
$val[$valoare_post] = $valoare_post_ex[1];
}else {
$val[$valoare_post] = $val[$valoare_post];
}
//print_r($val[$valoare_post]);
!$string or $string .= ", ";
$string .= '\'' . addslashes($val[$valoare_post]) . '\'';
}
}
}
$q_insert .= $string;
$q_insert .= ")";
//echo $q_insert;
$db->query($q_insert);
//die();
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//AICI VEDEM DACA AM TRIMIS ARRAYURI DE LIMBA
/* GET THE LAST ID INSERTED */
$queryw = "SELECT LAST_INSERT_ID()";
$dbw->query($queryw);
$dbw->next_record();
//echo "ssssss:".$LastInsertId = $dbw->f($table."_id");
$LastInsertId = $db->lastInsertId();
//die();
$campurig = "";
//print_p($valori_extra);die;
if(is_array($val['extratabels'])){
foreach($val['extratabels'] as $tabel=>$campuri) {
$q = "select * from " . PREFIX_TABLE . $tabel . "";
$result_u = $db->query($q);
$numar = $db->num_fields();
for ($i = 0; $i <= $numar - 1; $i++) {
$finfoT[] = $result_u->fetch_field_direct($i);
}
foreach ($finfoT as $ff) {
if ($ff->name != $table . "_id") {
$nume_campT[] = $ff->name;
$nume_cT[] = $ff->name;
}
}
}
//
$campuri_de_inserat[$table."_id"] = $LastInsertId;
foreach($nume_campT as $camps){
$campuri_de_inserat[$camps] = $valori_extra[$camps];
}
$q_insert_extra = "INSERT INTO ".PREFIX_TABLE.$tabel." (";
foreach($campuri_de_inserat as $campul=>$valoarea){
!$string2 or $string2 .= ", ";
$string2.= "`".$campul."`";
}
$q_insert_extra .=$string2 ;
$q_insert_extra .= ") VALUES (";
foreach($campuri_de_inserat as $campul=>$valoarea){
if (is_array($valoarea)) {
foreach ($valoarea as $final_de_inserat)
if($valoarea!="Array") {
$campurig .= $final_de_inserat . "|||";
}
$valoarea = $campurig;
//print_p($valoarea);
}
//echo $campurig;
!$string3 or $string3 .= ", ";
$string3 .= '\'' . addslashes($valoarea) . '\'';
$campurig = "";
}
$q_insert_extra .= $string3;
$q_insert_extra .= ")";
$db->query($q_insert_extra);
//echo $q_insert_extra;
//print_p($campuri_de_inserat);
//die;
}
//facem arrayuri cu campurile din tabelul auxiliar, ca sa nu incercam sa inseram in campuri inexistente
return $LastInsertId;
}
//----------------------------------------------------------------------------------------------------------------//
function update($id, $table, $val, $aux_table)
{
$id_refacut = explode(PREFIX_TABLE,$table);
//print_p($val);
//die;
global $campuri_data;
$db = new DB_Sql;
$q = "select * from ".PREFIX_TABLE.$table."";
$result = $db->query($q);
$numar = $db->num_fields();
for ($i = 0; $i <= $numar-1; $i++) {
$finfo[] = $result->fetch_field_direct($i);
}
foreach($finfo as $ff){
if($ff->name != $table."_id") {
if(array_key_exists($ff->name, $val)) {
$nume_camp[] = $ff->name;
}
}
}
//print_p($nume_camp);
//die();
// for($i = 1; $i<=$numar-1; $i++)
// {
// $nume_camp[] = $db->fieldName($i);
// }
$q_before_update = "UPDATE ".PREFIX_TABLE.$table." SET ";
foreach($nume_camp as $ke=>$v)
{
if ($v == 'parola') {
}
else {
!$str or $str .= ", ";
$str .= $v . " = ''";
}
}
$q_before_update = $q_before_update.$str;
$q_before_update = $q_before_update." where ".$table."_id =".$id;
//echo $q_before_update;die;
$db->query($q_before_update);
$q = "select * from ".PREFIX_TABLE.$table."";
$result_u = $db->query($q);
$numar = $db->num_fields();
for ($i = 0; $i <= $numar-1; $i++) {
$finfo[] = $result_u->fetch_field_direct($i);
}
foreach($finfo as $ff){
if($ff->name != $table."_id") {
$nume_camp[] = $ff->name;
}
}
//print_p($val);
//print_p($nume_camp);
$q_update = "UPDATE ".PREFIX_TABLE.$table." SET ";
settype($val,"array");
if(!is_array($val))
{
return false;
}
$lw = 1;
foreach ($val as $nume_camp=>$valoare_post) {
if($lw == 1){
$adrese = getAddressFromLatLng($val['gmapLat'], $val['gmapLng']);
}
if (is_array($valoare_post)) {
foreach ($valoare_post as $final_de_inserat)
if($valoare_post!="Array") {
$valoare_post .= $final_de_inserat . "|||";
}
}
else {
if($valoare_post!="Array") {
$valoare_post = $valoare_post;
}
}
if(in_array($nume_camp, $campuri_data)){
$timestamp = strtotime($valoare_post);
$valoare_post = date("Y-m-d H:i:s", $timestamp);
}
//echo $valoare_post;
if ($nume_camp == 'imagini_actuale') {
!$string or $string .= ", ";
$string .= "imagini = '" . $_POST['imagini_actuale'] . $_POST['imagini'] . "'";
} elseif ($nume_camp == 'documente_actuale') {
!$string or $string .= ", ";
$string .= "documente = '" . $_POST['documente_actuale'] . $_POST['documente'] . "'";
} elseif ($nume_camp == 'imagini') {
}elseif ($nume_camp == 'modificat_de') {
!$string or $string .= ", ";
$string .= "modificat_de = '" . $_SESSION['SESS_id'] . "'";
} elseif ($nume_camp == 'documente') {
} elseif ($nume_camp == 't') {
} elseif ($nume_camp == 'parola') {
} elseif ($nume_camp == 'parola1') {
}
elseif ($nume_camp == 'data') {
if ($_POST['data'] == "") {
!$string or $string .= ", ";
$string .= "data = NOW()";
} else {
!$string or $string .= ", ";
$string .= "data = '" . addslashes(($valoare_post)) . "'";
}
} /*elseif($nume_camp=='parola')
{
!$string or $string .= ", ";
$string.= "parola = '".MD5($_POST['parola'])."'";
}*/
elseif ($nume_camp == 'op') {
} //caz special limbi ============trebuie adaptat pentru formularele din care mai vine si altceva in afara de denumire
else
{
if (strpos($valoare_post, 'Array') !== false) {
$valoare_post_ex = explode("Array",$valoare_post);
$valoare_post = $valoare_post_ex[1];
}else {
$valoare_post = $valoare_post;
}
if ($nume_camp == "adresa"){$valoare_post = $adrese['adresa'];}
if ($nume_camp == "adresa_exacta"){$valoare_post = $adrese['adresa_exacta'];}
if ($nume_camp == "adresa_curata"){$valoare_post = $adrese['adresa_curata'];}
if ($nume_camp == "localitateGMAP"){$valoare_post = $adrese['localitateGMAP'];}
//print_p($valoare_post);
//echo "intram aici";
!$string or $string .= ", ";
$string .= $nume_camp . " = '" . addslashes(($valoare_post)) . "'";
}
$lw++;
}
$q_update = $q_update.$string;
$q_update = $q_update." where ".$table."_id ='". $id ."'";
//echo $q_update;
//die;
$db->query($q_update);
return $id;
}
//--------------------------------------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------------------------------------//
function delete($id, $table)
{
$db = new DB_Sql;
$q = "DELETE FROM ".PREFIX_TABLE.$table." WHERE ".$table."_id = '".$id."' ";
$db->query($q);
return $q;
}
function view($table, $order_by="")
{
$db = new DB_Sql;
$q = "SELECT * FROM ".PREFIX_TABLE.$table." ".$order_by." ";
$db->query($q);
return $q;
}
function viewRow($table, $id)
{
$q = "SELECT * FROM ".PREFIX_TABLE.$table." where ".$table."_id = ".$id."";
//echo $q;
return $q;
}
function viewRowSpecificField($table, $extrafield, $id)
{
$q = "SELECT * FROM ".PREFIX_TABLE.$table." where ".$extrafield." = ".$id."";
//echo $q;
return $q;
}
function getPagerData($numHits, $limit, $page)
{
$numHits = (int) $numHits;
$limit = max((int) $limit, 1);
$page = (int) $page;
$numPages = ceil($numHits / $limit);
$page = max($page, 1);
$page = min($page, $numPages);
$offset = ($page - 1) * $limit;
$ret = new stdClass;
$ret->offset = $offset;
$ret->limit = $limit;
$ret->numPages = $numPages;
$ret->page = $page;
return $ret;
}
function emptyBeforeUpdate($table)
{
$db = new DB_Sql;
$q = "select * from ".PREFIX_TABLE.$table."";
$db->query($q);
$numar = $db->num_fields();
for($i = 0; $i<=$numar-1; $i++)
{
$nume_camp[$db->fieldName($i)] = $db->fieldName($i);
}
return $nume_camp;
}
function close_conn()
{
//You're not useful to us anymore, good night
return mysql_close();
}
function getAddressFromLatLng($lat, $lng){
$db = new DB_Sql;
$url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" . $lat . "," . $lng . "&key=AIzaSyBA8s_txOVTEDv1flqMcyxa1C-Yuf6zT94";
$jsonData = file_get_contents($url);
$data = json_decode($jsonData);
//print_p($data);
//$xlat = $data->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
//$xlong = $data->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
$ceva = $data->{'results'}[0]->{'address_components'}[0]->{'long_name'};
$bulevard = $data->{'results'}[0]->{'address_components'}[1]->{'long_name'};
$sector = $data->{'results'}[0]->{'address_components'}[3]->{'long_name'};
$oras = $data->{'results'}[0]->{'address_components'}[4]->{'long_name'};
$cartier = $data->{'results'}[1]->{'address_components'}[0]->{'long_name'};
$adresa_exacta = $data->{'results'}[0]->{'formatted_address'};
if($sector == $oras){
$adresa = $cartier . ", " . $ceva.", ".$sector;
//echo "
";
//echo $adresa_completa;
}
else {
$adresa = $sector . ", " . $cartier . ", " . $bulevard . ", " . $oras;
//echo "
";
//echo $adresa_completa;
}
//scoatem localitatea legata de localitatea noastra din tabela localitate
foreach($data->results[0]->address_components as $ceva){
//print_p($ceva->types[0]);
if($ceva->types[0] == "locality"){
$denumireIdentica = $ceva->long_name;
}
}
//$adresa = $db->escape_string($adresa);
//$adresa_exacta = $db->escape_string($adresa_exacta);
$addr['localitateGMAP'] = $db->escape_string($denumireIdentica);
$addr['adresa'] = $db->escape_string($adresa);
$addr['adresa_exacta'] = $db->escape_string($adresa_exacta);
$addr['adresa_curata'] = $db->escape_string(scoateDiacritice($adresa_exacta));
return $addr;
}
?>
function nextPage($pager, $page, $table="")
{
$next_p = "