<?php
/*
* department.php, 2006
*
* bilin
* Copyright (C) 2006 Gokhan ALTINSOY hide@address.com
* http://gokhan.tubim.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Select License Info from the Help menu to view the terms and conditions of this license.
*/
require_once 'preheader.php';
$thisfile = "department.php?this=this";
$firsttable = "" . $GLOBALS['__TABLE_PRE__'] . "department";
$bBRICKobj = new biliBrick($thisfile,$firsttable);
$bBRICKobj->setrfield("departmentid");
$bBRICKobj->setidfield("id");
$rtables = array("" . $GLOBALS['__TABLE_PRE__'] . "persondepartment","" . $GLOBALS['__TABLE_PRE__'] . "departmentinfo");
$bBRICKobj->setrtables($rtables);
$usernamefield = array("name" => $c_user_table_usernamefield_name,"type" => "list", "sql" => "",
"idfield" => "id","issave" => "true" , "isfirst" => "true");
$namefield = array("name" => "name","type" => "list", "sql" => "",
"idfield" => "id","issave" => "true" , "isfirst" => "true");
$fnamefield = array("name" => "name","type" => "text" , "width" => "0","isnew" => "true",
"isoedit" => "true","isserc" => "true");
$extrafield = array("name" => "extra","type" => "textarea" , "rows" => "14","cols" => "60","issave" => "true",
"isedit" => "true","isinsert" => "true","isnew" => "true","isoedit" => "true"
,"isserc" => "true");
$datedfield = array("name" => "dated","type" => "text" , "width" => "0","isedit" => "true","isoedit" => "true"
,"isserc" => "true");
$statusfield = array("name" => "status","type" => "text" , "width" => "0",
"issave" => "true","isedit" => "true","isinsert" => "true");
$bBRICKobj->setfieldstotal(
array( "name" => $fnamefield , "extra" => $extrafield ,"dated" => $datedfield));
$bBRICKobj->setoperations(array('view','edit'));
$batchops = array('gotdepartment','delete');
$bBRICKobj->setbatchoperations($batchops);
$bBRICKobj->setdemoview($demoview);
$bBRICKobj->settablerowcount($tablerowcount);
$bDBobj = new biliDB();
$operation = $_GET['op'];
if ($bBRICKobj->IsInNoOutputController($operation)) {
$bBRICKobj->$operation();
}
require_once 'header.php';
print("<table border=0 align=\"left\" valign=\"top\">");
print("<tr><td><span class=\"companytitle\">" . biliCreateHtmlLinkNoOut($thisfile,"DEPARTMENTS") . "</span></td></tr>");
print("<tr><td>");
$bBRICKobj->permission();
print("</td></tr>");
print("<tr><td>");
$bBRICKobj->showAlertMessage();
print("</td></tr>");
if ($operation == '')
{
print("<tr><td>");
print("<table><tr valign=\"top\">");
if ($_SESSION['usertype'] == "admin") {
print("<td><span class=\"operation\">");
biliCreateHtmlLink($thisfile . "&op=add","Add new department");
print("</span></td>");
}
print("<td align=\"right\" width=\"500\">");
$fields = array('search');
biliCreateHtmlFormOneRow($fields,$thisfile . "&op=search","search");
print("</td>");
print("</tr></table>");
print("</td></tr>");
$sql = $bDBobj->biliSelectSql("*", $firsttable, "1");
$fields = array('name','extra','dated');
$countsql = $bDBobj->biliSelectSql("count(*) as count", $firsttable, "1");
$operations = array('view','edit');
print("<tr><td>");
$bDBobj->biliCreateHtmlTableForm($sql,$fields,$operations,$thisfile,$countsql, $_GET['start'],$tablerowcount,$batchops,"");
print("</td></tr>");
}
else if ($operation == 'view')
{
print("<tr><td>");
print("<table> <tr> <td>");
print("<table> <tr>");
$bBRICKobj->departmentbasicinfo();
if ($_SESSION['usertype'] == "admin") {
print("<td><span class=\"operation\">");
biliCreateHtmlLink($thisfile . "&op=edit&itemid="
. $_GET['itemid'],"edit");
print("</span></td>");
}
$_SESSION["urlredirect"] = $_SERVER['REQUEST_URI'];
print("</tr></table> ");
print("</td></tr><tr><td>");
$bBRICKobj->printline();
print("</td></tr><tr><td>");
print("<table class=\"bilitablemidup\"> <tr>");
print("<td><span class=\"bottomtext\">");
biliCreateHtmlLink($thisfile . "&op=view&subop=viewsub&viewtablename=" . $GLOBALS['__TABLE_PRE__'] . "persondepartment&itemid="
. $_GET['itemid'],"People in this department");
print("</span></td>");
print("<td><span class=\"bottomtext\">");
biliCreateHtmlLink($thisfile . "&op=view&subop=viewsub&viewtablename=" . $GLOBALS['__TABLE_PRE__'] . "departmentinfo&itemid="
. $_GET['itemid'],"Information in this department");
print("</span></td>");
print("</tr></table>");
print("</td></tr><tr><td>");
// this part describes relational tables
$bBRICKobj->setoperations(array('viewedit','viewdelete'));
if ($_GET["subop"] == "") {
$_GET["subop"] = "viewsub";
$_GET["viewtablename"] = "" . $GLOBALS['__TABLE_PRE__'] . "persondepartment";
}
// table " . $GLOBALS['__TABLE_PRE__'] . "person
$bBRICKobj->setrtitle("People in this department");
// $bBRICKobj->setraddtitle("Add new person");
$bBRICKobj->setrsecondaddtitle("");
$bBRICKobj->setsecondtable($c_user_table_name);
$bBRICKobj->setsecondtableid($c_user_table_idfield_name);
$bBRICKobj->setrelationtable("" . $GLOBALS['__TABLE_PRE__'] . "persondepartment");
$bBRICKobj->setsecondtablekey("personid");
$usernamefield["sql"] = "SELECT * FROM " . $c_user_table_name;
$bBRICKobj->setviewfieldstotal(
array( "username" => $usernamefield ,"status" => $statusfield, "extra" => $extrafield ,"dated" => $datedfield));
$bBRICKobj->setrfile("person.php");
$bBRICKobj->viewrelation2();
// table " . $GLOBALS['__TABLE_PRE__'] . "info
$bBRICKobj->setrtitle("Information in this department");
// $bBRICKobj->setraddtitle("Add new information");
$bBRICKobj->setrsecondaddtitle("");
$bBRICKobj->setsecondtable("" . $GLOBALS['__TABLE_PRE__'] . "info");
$bBRICKobj->setsecondtableid("id");
$bBRICKobj->setrelationtable("" . $GLOBALS['__TABLE_PRE__'] . "departmentinfo");
$bBRICKobj->setsecondtablekey("infoid");
$namefield["sql"] = "SELECT * FROM " . "" . $GLOBALS['__TABLE_PRE__'] . "info";
$bBRICKobj->setviewfieldstotal(
array( "name" => $namefield ,"extra" => $extrafield ,"dated" => $datedfield));
$bBRICKobj->setrfile("information.php");
$bBRICKobj->viewrelation2();
print("</td></tr><tr><td>");
// table " . $GLOBALS['__TABLE_PRE__'] . "info that nobody has
print("<br/><br/>");
print("<table><tr>");
print("<td><b>");
biliCreateHtmlText("Information that nobody has in this department");
print("</b></td>");
print("<td>");
print("</td>");
print("</tr></table>");
/*
$sql = "select " . $GLOBALS['__TABLE_PRE__'] . "info.name, " . $GLOBALS['__TABLE_PRE__'] . "info.content
from " . $GLOBALS['__TABLE_PRE__'] . "info, " . $GLOBALS['__TABLE_PRE__'] . "departmentinfo
where " . $GLOBALS['__TABLE_PRE__'] . "departmentinfo.departmentid="
. $_GET['itemid'] . " and " . $GLOBALS['__TABLE_PRE__'] . "info.id=" . $GLOBALS['__TABLE_PRE__'] . "departmentinfo.infoid
and " . $GLOBALS['__TABLE_PRE__'] . "info.id not in
(select " . $GLOBALS['__TABLE_PRE__'] . "info.id
from " . $GLOBALS['__TABLE_PRE__'] . "person, " . $GLOBALS['__TABLE_PRE__'] . "persondepartment, " . $GLOBALS['__TABLE_PRE__'] . "info, " . $GLOBALS['__TABLE_PRE__'] . "personinfo
where " . $GLOBALS['__TABLE_PRE__'] . "persondepartment.departmentid="
. $_GET['itemid'] . " and " . $GLOBALS['__TABLE_PRE__'] . "persondepartment.personid = " . $GLOBALS['__TABLE_PRE__'] . "personinfo.personid and " . $GLOBALS['__TABLE_PRE__'] . "info.id=" . $GLOBALS['__TABLE_PRE__'] . "personinfo.infoid
group by " . $GLOBALS['__TABLE_PRE__'] . "info.id)";
*/ //full query didn't work old mysql versions
$sql2= "select " . $GLOBALS['__TABLE_PRE__'] . "info.id
from " . $c_user_table_name . ", " . $GLOBALS['__TABLE_PRE__'] . "persondepartment, " . $GLOBALS['__TABLE_PRE__'] . "info, " . $GLOBALS['__TABLE_PRE__'] . "personinfo
where " . $GLOBALS['__TABLE_PRE__'] . "persondepartment.departmentid="
. $_GET['itemid'] . " and " . $GLOBALS['__TABLE_PRE__'] . "persondepartment.personid = " . $GLOBALS['__TABLE_PRE__'] . "personinfo.personid and " . $GLOBALS['__TABLE_PRE__'] . "info.id=" . $GLOBALS['__TABLE_PRE__'] . "personinfo.infoid
group by " . $GLOBALS['__TABLE_PRE__'] . "info.id";
$row = $bDBobj->biliGetFieldAsArray($sql2,"id");
$sql = "select " . $GLOBALS['__TABLE_PRE__'] . "info.name, " . $GLOBALS['__TABLE_PRE__'] . "info.content
from " . $GLOBALS['__TABLE_PRE__'] . "info, " . $GLOBALS['__TABLE_PRE__'] . "departmentinfo
where " . $GLOBALS['__TABLE_PRE__'] . "departmentinfo.departmentid="
. $_GET['itemid'] . " and " . $GLOBALS['__TABLE_PRE__'] . "info.id=" . $GLOBALS['__TABLE_PRE__'] . "departmentinfo.infoid ";
if($row != '') $sql = $sql . " and " . $GLOBALS['__TABLE_PRE__'] . "info.id not in (" . $row . ")";
$fields = array('name','content');
$operations = array();
print("</td></tr><tr><td>");
$bDBobj->biliCreateHtmlRow($sql,$fields,$operations,$thisfile);
print("<br/><br/>");
print("</td></tr><tr><td>");
$bBRICKobj->printline();
print("</td></tr><tr><td>");
print("<table> <tr>");
$bBRICKobj->departmentextrainfo();
print("</tr> </table> ");
print("</td></tr></table> ");
print("</td></tr>");
}
else if ($bBRICKobj->IsInController($operation)) {
print("<tr><td>");
$bBRICKobj->$operation();
print("</td></tr>");
}
print("</table");
require_once 'footer.php';
?>