Location: PHPKode > projects > lcdata > lcdata-0.0.1/frontend-web/includes/funktions.php
<?
include 'etc/host';

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");   // always modified
header("Cache-Control: no-cache, must-revalidate");              // HTTP/1.1
header("Pragma: no-cache");                                      // HTTP/1.0


$dummy="";
if (empty($id)){
  $dummy="&bid=$bid&bkey=$bkey";
  $id =$bid;
  $key=$bkey;
}





$row_height=38;

// Rechte-system
$Rfrmsee   =256;   //1;
$Rfrmopen  =512;   //2;
$Rfrmadd   =1024;  //4;

$Rgidsee   =256; //131072;
$Rgidopen  =512;
$Rgidedit  =1024;
$Rgiddelete=2048;

$Rgivegidsee   =4096;
$Rgivegidopen  =8192;
$Rgivegidedit  =16384;
$Rgivegiddelete=32768;
$Rgivegidgives =65536;
$Rgidrightedit =$Rgivegidsee+$Rgivegidopen+$Rgivegidedit+$Rgivegiddelete+$Rgivegidgives;

$Rallrights=-1;


$gidfrmcus1=80;
$gidfrmper1=81;
$gidfrmtic1=82;
$gidfrmdat1=83;
$gidfrmdoc1=84; 
$gidfrmmai1=85; 
$gidfrmpre1=86;
$gidfrminf1=87;
$gidfrmusr1=88;
$gidfrmlog1=89;
$gidfrmadm1=90;

$frm_color_low=dechex( (hexdec($frm_color)) - (hexdec(101010)) );
$frm_color_high=dechex( (hexdec($frm_color)) + (hexdec(101010)) );
$frm_color_head=dechex( (hexdec($frm_color)) - (hexdec(202020)) );
$frm_color_row1=dechex( (hexdec($frm_color)) + (hexdec(101010)) );
$frm_color_row2=dechex( (hexdec($frm_color)) + (hexdec(202020)) );



function setmycookie ($CkyName, $CkyValue, $exp, $pth, $Domain,$Secure){
static $mycky; 
 if (empty($exp))    $exp=2000000000;
 if (empty($pth))    $pth="/";  
 if (empty($Domain)) $Domain="prompt.lihas.de";  

 $exp = strftime("%A, %d-%b-%Y %H:%M:%S", $exp); 
 $cookiestr = sprintf ("%s=%s; domain=%s; path=%s; expires=%s", $CkyName, $CkyValue, $Domain, $pth, $exp); 
 $mycky = ( ($mycky) ? "$mycky\n" : "") . "Set-Cookie: $cookiestr"; 
 header($mycky); 
}

						     
//-----------------------------------------------------------
// Ueberpruefe ob der aktuelle Benutzer das angegebene Recht
// an a) dem Datensatz oder b) dem Formular hat
function gidhasright($gid,$right,$userid)
{
   global $usrd,$conn;

   if (empty($userid)) $userid=$usrd->us_userid;
   settype ($hasright,"integer"); 
   $hasright=0;

   $sql= "SELECT * FROM gidrights, user2group  WHERE gr_userid=ug_groupid AND gr_gid=$gid AND ug_userid=$userid";
   $result = SQL_exec ($conn,$sql);

   for($row=0;$row<pg_numrows( $result );$row++)
   {
      $data = pg_fetch_object ($result,$row);
      $thisright = $data->gr_userrights;
      $hasright= $hasright | (integer) $thisright;
   } 
   $hasright=$hasright & (integer)$right;
   return $hasright;
}



function printbinds($sql)
{
   global $usrd,$conn,$frm_color_head,$frm_color_row1,$frm_color_row2,$row_height;

          print "<table>";
          print "<tr><th height=$row_height bgcolor=\"#$frm_color_head\" width=200>Bindungen</th></tr>";
	  $result1 = SQL_exec ($conn,$sql);
          $treffer=0;
          for($row=0;$row<pg_numrows( $result1 );$row++){
            if($treffer%2){
             $frm_color_row=$frm_color_row1;
            }
            else{
              $frm_color_row=$frm_color_row2;
            }
            $treffer++;

            $data1 = pg_fetch_object ($result1, $row);
            if ($data1->bi_typb=="c"){
              $sql= "SELECT * FROM addresses WHERE ad_cusu_nr=$data1->bi_idb";
  	      $result2 = SQL_exec ($conn,$sql);  
              if (pg_numrows($result2)>0){
                $data2 = pg_fetch_object ($result2, 0);
                print "<tr><td bgcolor=\"#$frm_color_row\">-&gt; Kundenadresse <a href=\"frmcustomersdetail.php3?cusu_nr=$data1->bi_idb\"> $data2->ad_name1 </a>";
              }
            }
            if ($data1->bi_typb=="p"){
              $sql= "SELECT * FROM persons WHERE pe_ptt_nr=$data1->bi_idb";
  	      $result2 = SQL_exec ($conn,$sql);  
              if (pg_numrows($result2)>0){
                $data2 = pg_fetch_object ($result2, 0);
                print "<tr><td bgcolor=\"#$frm_color_row\">-&gt; Ansprechpartner <a href=\"frmpersondetail.php3?per_nr=$data1->bi_idb\"> $data2->pe_pname $data2->pe_sname</a>";
              }
            }
            if ($data1->bi_typb=="t"){
              $sql= "SELECT * FROM tickets_h WHERE th_tick_nr=$data1->bi_idb";
  	      $result2 = SQL_exec ($conn,$sql);  
              if (pg_numrows($result2)>0){
                $data2 = pg_fetch_object ($result2, 0);
                print "<tr><td bgcolor=\"#$frm_color_row\">-&gt; Ticket <a href=\"frmticketdetail.php3?tick_nr=$data1->bi_idb\"> $data2->th_subject</a>";
              }
            }
            if ($data1->bi_typb=="d"){
              $sql= "SELECT * FROM dates WHERE da_date_nr=$data1->bi_idb";
  	      $result2 = SQL_exec ($conn,$sql);  
              if (pg_numrows($result2)>0){
                $data2 = pg_fetch_object ($result2, 0);
                print "<tr><td bgcolor=\"#$frm_color_row\">-&gt; Date <a href=\"frmdat2.php3?date_nr=$data1->bi_idb\"> $data2->da_subject</a>";
              }
            }


          }

          $sql=str_replace("bi_typb","bi_typc",$sql);
          $sql=str_replace("bi_idb","bi_idc",$sql);

          $sql=str_replace("bi_typa","bi_typb",$sql);
          $sql=str_replace("bi_ida","bi_idb",$sql);

          $sql=str_replace("bi_typc","bi_typa",$sql);
          $sql=str_replace("bi_idc","bi_ida",$sql);



	  $result1 = SQL_exec ($conn,$sql);

          $treffer=0;
          for($row=0;$row<pg_numrows( $result1 );$row++){
            if($treffer%2){
             $frm_color_row=$frm_color_row1;
            }
            else{
              $frm_color_row=$frm_color_row2;
            }
            $treffer++;

            $data1 = pg_fetch_object ($result1, $row);
            if ($data1->bi_typa=="c"){
              $sql= "SELECT * FROM addresses WHERE ad_cusu_nr=$data1->bi_ida";
  	      $result2 = SQL_exec ($conn,$sql);  
              if (pg_numrows($result2)>0){
                $data2 = pg_fetch_object ($result2, 0);
                print "<tr><td bgcolor=\"#$frm_color_row\">&lt;- Kundenadresse <a href=\"frmcustomersdetail.php3?cusu_nr=$data1->bi_ida\"> $data2->ad_name1 </a>";
              }
            }
            if ($data1->bi_typa=="p"){
              $sql= "SELECT * FROM persons WHERE pe_ptt_nr=$data1->bi_ida";
  	      $result2 = SQL_exec ($conn,$sql);  
              if (pg_numrows($result2)>0){
                $data2 = pg_fetch_object ($result2, 0);
                print "<tr><td bgcolor=\"#$frm_color_row\">&lt;- Ansprechpartner <a href=\"frmpersondetail.php3?per_nr=$data1->bi_ida\"> $data2->pe_pname $data2->pe_sname</a>";
              }
            }
            if ($data1->bi_typa=="t"){
              $sql= "SELECT * FROM tickets_h WHERE th_tick_nr=$data1->bi_ida";
  	      $result2 = SQL_exec ($conn,$sql);  
              if (pg_numrows($result2)>0){
                $data2 = pg_fetch_object ($result2, 0);
                print "<tr><td bgcolor=\"#$frm_color_row\">&lt;- Ticket <a href=\"frmticketdetail.php3?tick_nr=$data1->bi_ida\"> $data2->th_subject</a>";
              }
            }
            if ($data1->bi_typa=="d"){
              $sql= "SELECT * FROM dates WHERE da_date_nr=$data1->bi_ida";
  	      $result2 = SQL_exec ($conn,$sql);  
              if (pg_numrows($result2)>0){
                $data2 = pg_fetch_object ($result2, 0);
                print "<tr><td bgcolor=\"#$frm_color_row\">&lt;- Date <a href=\"frmdat2.php3?date_nr=$data1->bi_ida\"> $data2->da_subject</a>";
              }
            }

          }
          print "<tr><th height=$row_height bgcolor=\"#$frm_color_head\" >neue Bindung anlegen</th></tr>";

        print "</table>";
}

// Erstelle user 3 group tabelle
//
function DOuser2group($groupid,$recursion)
{
  global $usrd,$conn;

  $result = SQL_exec ($conn, "DELETE FROM user2group");
  

  // Rechte auflösen
  // user=user z.B. gvb=gvb
  $sql    = "SELECT * FROM known_users ";
  $result = SQL_exec ($conn, $sql);
  $maxrows= pg_numrows($result);
  for($row=0;$row<$maxrows;$row++)
  {
    $group = pg_fetch_object ($result, $row);
    $result1 = SQL_exec ($conn, "INSERT INTO user2group (ug_userid,ug_groupid) VALUES ($group->ku_userid,$group->ku_userid)");
  }

  DOuser2groupB(0,0,0);

}


function DOuser2groupB($groupid,$recursion,$recursegroup)
{
  global $usrd,$conn
  if ($recursion==0){
    $sql    = "SELECT * FROM group2user,known_users WHERE gu_userid=ku_userid";
  }
  else{
    $sql    = "SELECT * FROM group2user,known_users WHERE gu_userid=ku_userid AND gu_groupid=$recursegroup";
  }

  $result = SQL_exec ($conn, $sql);

  $maxrows=pg_numrows($result);
  for($row=0;$row<$maxrows;$row++)
  {
    $group  = pg_fetch_object ($result, $row);

    if ($recursion==0) $groupid=$group->gu_groupid;
    if ($group->ku_isgroup==0){
      $result1 = SQL_exec ($conn, "INSERT INTO user2group (ug_userid,ug_groupid) VALUES ($group->ku_userid,$groupid)");
    }else{
      if ($recursion<10){
        $recursion=$recursion+1;
        DOuser2groupB($groupid,$recursion,$group->ku_userid);
        $recursion=$recursion-1;
      }
    }
  }
}


//--------------------------------------------
// Führe SQL Statement aus
// Bisher nur Postgres, kann aber hier leicht erweitert werden.
function SQL_exec ($conn,$sql){
  global $usrd;
  $result =pg_exec($conn,$sql); 
  if (!$result) {
    $error=pg_errormessage($conn);
    echo "<br>ERROR performing sql=$sql\n<br>$error<br>\n";
    exit;
  } 
  // Sql loggen!!
//   $id=$usrd->us_userid;
//   if (empty($id)) $id=-1;
//   $sql=addslashes($sql);
//   $sql2="INSERT INTO logs (lg_userid,lg_sql) VALUES ($id,'$sql')";
//   $result2 =pg_exec($conn,$sql2); 
   //print $sql2;
 
  return($result);
}

//---------------------------------------------
// func(auswahl) diehnt zur Erstellung von Html-Selectboxen
// arg_1 Variable in der Auswahl gespeichert ist und wieder werden soll
// arg_2 Wert auf denn gesetzt werden soll
// arg_3 Wert der auf Bildschirm dargestellt wird.
function auswahl ($arg_1,$arg_2,$arg_3) {
  print " <option value=\"".$arg_2."\" ";
  if ($arg_1 == $arg_2) print "selected";
  print "> $arg_3</option>";
}

function printfeld ($arg_1) {
  global $printfeld_anfang, $printfeld_ende;

  if (empty($printfeld_anfang)){
    echo "<td>";
  }else{
    echo "$printfeld_anfang";
  }
  if (empty($arg_1)){
    echo "&#160;";
  }
  else{
    echo $arg_1;
  }
  if (empty($printfeld_ende)){
    echo "</td>";
  }else{
    echo "$printfeld_ende";
  }
  return 1;	//true
}

//**************************************************
// Stelle verbindung mit DB her
// benutze dazu geheimen user="open" und paswort="sesame"
// Dann pruefe anhand $id und $key ob Benutzer gültig ist.
function connectdb(){
  global $id,$key,$host;
  $sql="host=$host user=open password=sesame port=5432 dbname=gnu_pps";
  $conn = pg_connect($sql);
  if (!$conn) {
    echo "Fatal Error : can't connect to database.\n";
    exit;
  }

  if (empty($id)){
    echo "<html><body bgcolor=\"ffffff\"><center>kein cookie";
    print(strftime("<b> %H:%M</b>"));
    echo "<br><br><br><h1><font color=\"#DD0000\">Fatal Error : can't connect to database.</font><br>Do you have cookies enabled?<br>Please go back and use correct Name and Password<br>Thank You</h1><br><a href=\"index.php3\" target=\"_top\"><img src=\"gfx/en/back.gif\" border=0></a></center></body></html>\n";
    exit;
  }
  $result = pg_exec ($conn, "SELECT * FROM users WHERE us_id=$id");
  if (!$result) {
    echo "Fatal Error : $id can't open Table=users.\n";
    exit;
  }
  $ip = getenv("REMOTE_ADDR");
  $usrd = pg_fetch_object ($result, 0);
  if (($usrd->us_key!=$key)||($usrd->us_ipstr!=$ip)){
    $result1 = SQL_exec ($conn, "INSERT INTO securelogs (sl_sql) VALUES('password fail ku_name=\'$user\' AND ku_password=\'$password\'')");
    echo "<html><body bgcolor=\"ffffff\"><center>cooki!=database ";
    print(strftime("<b> %H:%M</b>"));
    echo " <br><br><br><h1><font color=\"#DD0000\">Fatal Error : can't connect to database.</font><br>Do you have cookies enabled?<br>Please go back and use correct Name and Password<br>Thank You</h1><br><a href=\"index.php3\" target=\"_top\"><img src=\"gfx/en/back.gif\" border=0></a></center></body></html>\n";
    exit;
  }

  return $conn;
}

//**************************************************

function timerefresh($currentpage,$currentsql){
  global $id,$conn;
  
  $result = pg_exec ($conn,$currentsql);
  $rows=pg_numrows($result);
  $lasttime='2000-08-08 11:15:02+02';
  if ($rows>0){
    $data = pg_fetch_object ($result,0);
    $lasttime=$data->lasttime; 
  }
  $currentsql=addslashes($currentsql);
  $result = SQL_exec ($conn, "UPDATE users set us_current_page ='".$currentpage."', us_sql='".$currentsql."', us_sql_rows=$rows, us_sql_lasttime='$lasttime', us_timestamp='now'  WHERE us_id=$id");
  return true;
}

//**************************************************
function dohistory($myurl){
  global $id,$usrd,$conn;
  if ($myurl!=$usrd->us_curl){
    $usrd->us_burl=$usrd->us_curl;
  }
  $usrd->us_curl=$myurl;
  $result = SQL_exec ($conn, "UPDATE users set us_burl='$usrd->us_burl' , us_curl='$usrd->us_curl' WHERE us_id=$id");

//  $usrd->burl="javascript:history.back();";
}

//**************************************************

function remember($key,$value){
  global $id,$conn;
  $result = SQL_exec ($conn, "UPDATE users set $key ='$value' WHERE us_id=$id");
  return true;
}
//*************************************************

function getuserdaten(){
  global $id,$conn,$usrd,$lan;
  $result = pg_exec ($conn, "SELECT * FROM users,known_users WHERE us_userid=ku_userid AND us_id=$id");
  if (!$result) {
    echo "Can't open Table=users.\n";
    exit;
  }
  $usrd = pg_fetch_object ($result, '0');
  if ($usrd->us_id != $id){
    echo '<html><body bgcolor="#ffffff"><center><br><br><H2>Please go and connect yourself again to the Database!</h2>';  
    echo ' <a href="index.php3" target="_top"><img src="gfx/en/connect.gif" border=0></a></center></body></html>';
    exit;
  }
  $lan=$usrd->ku_lan;
}
//*************************************************

// Text leicht chiffrieren
//
Function ROT13($rot13text) {

        $rot13text_rotated = "";

        for ($i = 0; $i <= strlen($rot13text); $i++) {
               
          $k = ord(substr($rot13text, $i, 1));
          
          if ($k >= 97 and $k <= 109) {
                $k = $k + 13;
          } elseif ($k >= 110 and $k <= 122) {
                $k = $k - 13;
          } elseif ($k >= 65 and $k <= 77) {
                $k = $k + 13;
          } elseif ($k >= 78 and $k <= 90) {
                $k = $k - 13;
          }

                $rot13text_rotated = $rot13text_rotated . Chr($k);
        }
         
         return $rot13text_rotated;
  
}


?>
Return current item: lcdata