Commit 4b4d8c76 authored by sylvieg's avatar sylvieg

backquote in queries + getOne

parent a8194401
......@@ -13,11 +13,11 @@ class FileGalLib extends TikiLib {
function remove_file($id)
{
global $fgal_use_dir;
$path = $this->getOne("select path from tiki_files where fileId=$id");
$path = $this->getOne("select `path` from `tiki_files` where `fileId`=$id");
if($path) {
unlink($fgal_use_dir.$path);
}
$query = "delete from tiki_files where fileId=$id";
$query = "delete from `tiki_files` where `fileId`=$id";
$result = $this->query($query);
return true;
}
......@@ -35,14 +35,14 @@ class FileGalLib extends TikiLib {
$description = addslashes(strip_tags($description));
$data = addslashes($data);
$now = date("U");
if($this->getOne("select count(*) from tiki_files where hash='$checksum'")) return false;
if($this->getOne("select count(*) from `tiki_files` where `hash`='$checksum'")) return false;
$query = "insert into tiki_files(galleryId,name,description,filename,filesize,filetype,data,user,created,downloads,path,hash)
$query = "insert into `tiki_files`(`galleryId`,`name`,`description`,`filename`,`filesize`,`filetype`,`data`,`user`,`created`,`downloads`,`path`,`hash`)
values($galleryId,'$name','$description','$filename',$size,'$type','$data','$user',$now,0,'$path','$checksum')";
$result = $this->query($query);
$query = "update tiki_file_galleries set lastModif=$now where galleryId=$galleryId";
$query = "update `tiki_file_galleries` set `lastModif`=$now where `galleryId`=$galleryId";
$result = $this->query($query);
$query = "select max(fileId) from tiki_files where created=$now";
$query = "select max(`fileId`) from `tiki_files` where `created`=$now";
$fileId = $this->getOne($query);
return $fileId;
}
......@@ -72,18 +72,16 @@ class FileGalLib extends TikiLib {
if($find) {
$find = $this->qstr('%'.$find.'%');
if(empty($whuser)) {
$whuser = "where name like $find or description like $find";
$whuser = "where `name` like $find or `description` like $find";
} else {
$whuser .= " and name like $find or description like $find";
$whuser .= " and `name` like $find or `description` like $find";
}
}
$query = "select * from tiki_file_galleries $whuser order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_file_galleries $whuser";
$query = "select * from `tiki_file_galleries` $whuser order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from `tiki_file_galleries` $whuser";
$result = $this->query($query);
$result_cant = $this->query($query_cant);
$res2 = $result_cant->fetchRow();
$cant = $res2[0];
$cant = $this->getOne($query_cant);
$ret = Array();
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$aux = Array();
......@@ -98,7 +96,7 @@ class FileGalLib extends TikiLib {
$aux["user"] = $res["user"];
$aux["hits"] = $res["hits"];
$aux["public"] = $res["public"];
$aux["files"] = $this->getOne("select count(*) from tiki_files where galleryId='$gid'");
$aux["files"] = $this->getOne("select count(*) from `tiki_files` where `galleryId`='$gid'");
$ret[] = $aux;
}
if($old_sort_mode == 'files asc') {
......@@ -119,14 +117,14 @@ class FileGalLib extends TikiLib {
function set_file_gallery($file,$gallery)
{
$query = "update tiki_files set galleryId=$gallery where fileId=$file";
$query = "update `tiki_files` set `galleryId`=$gallery where `fileId`=$file";
$this->query($query);
}
function remove_file_gallery($id)
{
global $fgal_use_dir;
$query = "select path from tiki_files where galleryId='$id'";
$query = "select `path` from `tiki_files` where `galleryId`='$id'";
$result = $this->query($query);
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$path = $res["path"];
......@@ -134,9 +132,9 @@ class FileGalLib extends TikiLib {
@unlink($fgal_use_dir.$path);
}
}
$query = "delete from tiki_file_galleries where galleryId='$id'";
$query = "delete from `tiki_file_galleries` where `galleryId`='$id'";
$result = $this->query($query);
$query = "delete from tiki_files where galleryId='$id'";
$query = "delete from `tiki_files` where `galleryId`='$id'";
$result = $this->query($query);
$this->remove_object('file gallery',$id);
return true;
......@@ -144,7 +142,7 @@ class FileGalLib extends TikiLib {
function get_file_gallery_info($id)
{
$query = "select * from tiki_file_galleries where galleryId='$id'";
$query = "select * from `tiki_file_galleries` where `galleryId`='$id'";
$result = $this->query($query);
$res = $result->fetchRow(DB_FETCHMODE_ASSOC);
return $res;
......@@ -158,15 +156,15 @@ class FileGalLib extends TikiLib {
$description = addslashes(strip_tags($description));
$now = date("U");
if($galleryId>0) {
$query = "update tiki_file_galleries set name='$name', maxRows=$maxRows, description='$description',lastModif=$now, public='$public', visible='$visible',show_icon='$show_icon',show_id='$show_id',show_name='$show_name',show_description='$show_description',show_size='$show_size',show_created='$show_created',show_dl='$show_dl',max_desc=$max_desc where galleryId=$galleryId";
$query = "update `tiki_file_galleries` set `name`='$name', `maxRows`=$maxRows, `description`='$description',`lastModif`=$now, `public`='$public', `visible`='$visible',`show_icon`='$show_icon',`show_id`='$show_id',`show_name`='$show_name',`show_description`='$show_description',`show_size`='$show_size',`show_created`='$show_created',`show_dl`='$show_dl',`max_desc`=$max_desc where `galleryId`=$galleryId";
$result = $this->query($query);
} else {
// Create a new record
$query = "insert into tiki_file_galleries(name,description,created,user,lastModif,maxRows,public,hits,visible,show_id,show_icon,show_name,show_description,show_created,show_dl,max_desc)
$query = "insert into `tiki_file_galleries`(`name`,`description`,`created`,`user`,`lastModif`,`maxRows`,`public`,`hits`,`visible`,`show_id`,`show_icon`,`show_name`,`show_description`,`show_created`,`show_dl`,`max_desc`)
values ('$name','$description',$now,'$user',$now,$maxRows,'$public',0,'$visible',
'$show_id','$show_icon','$show_name','$show_description','$show_created','$show_dl',$max_desc)";
$result = $this->query($query);
$galleryId=$this->getOne("select max(galleryId) from tiki_file_galleries where name='$name' and lastModif=$now");
$galleryId=$this->getOne("select max(`galleryId`) from `tiki_file_galleries` where `name`='$name' and `lastModif`=$now");
}
return $galleryId;
}
......@@ -236,7 +234,7 @@ class FileGalLib extends TikiLib {
// Added by LeChuck, May 2, 2003
function get_file_info($id) {
$query = "select * from tiki_files where fileId='$id'";
$query = "select * from `tiki_files` where `fileId`='$id'";
$result = $this->query($query);
$res = $result->fetchRow(DB_FETCHMODE_ASSOC);
return $res;
......@@ -247,14 +245,14 @@ class FileGalLib extends TikiLib {
// Update the fields in the database
$name = addslashes(strip_tags($name));
$description = addslashes(strip_tags($description));
$query = "update tiki_files set name='$name', description='$description' where fileId=$id";
$query = "update `tiki_files` set `name`='$name', `description`='$description' where `fileId`=$id";
$result = $this->query($query);
// Get the gallery id for the file and update the last modified field
$now = date("U");
$galleryId = $this->getOne("select galleryId from tiki_files where fileId='$id'");
$galleryId = $this->getOne("select `galleryId` from `tiki_files` where `fileId`='$id'");
if ($galleryId) {
$query = "update tiki_file_galleries set lastModif=$now where galleryId=$galleryId";
$query = "update `tiki_file_galleries` set `lastModif`=$now where `galleryId`=$galleryId";
$this->query($query);
}
return $result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment