next up previous contents
Next: menugraf.php4 Up: Quellcode Previous: profile.php4   Contents


check_profile.php4


<?php
  /*******************************************
  /* Programm check_profile.php4
  /* checks data entered in profile.php4
  /* (c) Copyright 2002, Jens Bierkandt
  /* e-mail: jens@bierkandt.org
  /* Entstanden im Rahmen meiner Diplomarbeit
  /*******************************************
  */
  error_reporting(63); // 0 = none, 63 = full
  include("./config.php4");
  // connect to database
  $db = mysql_connect($hostname, $username, $password);
  mysql_select_db($database, $db);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>Analyse und Administration</title>
</head>
<body>
<center><a href="http://www.tu-ilmenau.de">
<img src="tu_header.jpg" width=574 height=40 align="middle"
  border=0></a >
<h1>Kontrolle der Profileingabe</h1>
<br><br>
<?php
  $errorstr = "";
  // check if name of table already exists
  if ((!isset($change)) AND $table != "") {
    $result = mysql_query("SELECT table_name FROM `admin`
      WHERE table_name=\"$table\"", $db);
    $row = mysql_fetch_row($result);
    echo mysql_error($db);
    $table_check = $row[0];
    if ($table_check) $errorstr .= "Tabellenname schon
      vorhanden<br>\n";
  }
  // Check the entered variables
  if ($name == "")
  $errorstr .= "Name der Anlage fehlt<br>\n";
  if ($computer == "")
  $errorstr .= "Name des Messcomputers fehlt<br>\n";
  if ($computer != "") {
    $result = mysql_query("SELECT `computer`,`table_name`
      FROM `admin` WHERE computer=\"$computer\"", $db);
    $row = mysql_fetch_row($result);
    echo mysql_error($db);
    $computer_check = $row[0];
    $table_check = $row[1];
    if ($computer_check) {
      if (!isset($change) OR ($table_check  != $table))
      $errorstr .= "Computername schon vorhanden<br>\n";
    }
  }
  if ($table == "")
  $errorstr .= "Name der Datentabelle fehlt<br>\n";
  if ($phone == "")
  $errorstr .= "Telefonnummer der Anlage fehlt<br>\n";
  if (preg_match("/.*\D/", $phone) == true)
  $errorstr .= "Telefonnummer enthält ungültige
    Zeichen<br>\n";
  if ($user == "")
  $errorstr .= "Name des Logins auf dem Messcomputer
    fehlt<br>\n";
  if ($passwd == "")
  $errorstr .= "Passwort des Logins fehlt\n";
  if ($passwd1 == "")
  $errorstr .= "Passwortwiederholung des Logins fehlt\n";
  if ($passwd != $passwd1)
  $errorstr .= "Passwortwiederholung ist falsch\n";
  if (!$errorstr) // Erverything seems to be ok
  {
    mysql_query("replace into admin values(\"$name\",
      \"$computer\" ,
    \"$table\", \"$phone\", \"$protocol\", \"$user\",
      ENCODE(\"$passwd\",\"$secret_key\"))", $db);
    echo mysql_error($db);
    if (!isset($change)) // new entry, new data table needs
      to be created
    {
      mysql_query("
      CREATE TABLE $table (
      id bigint(20) unsigned NOT NULL,
      timestamp datetime NOT NULL default '0000-00-00
        00:00:00',
      mictime double unsigned NOT NULL default '0',
      sensor1 tinyint(3) unsigned NULL,
      sensor2 tinyint(3) unsigned NULL,
      sensor3 tinyint(3) unsigned NULL,
      sensor4 tinyint(3) unsigned NULL,
      sensor5 tinyint(3) unsigned NULL,
      sensor6 tinyint(3) unsigned NULL,
      PRIMARY KEY  (id),
      UNIQUE KEY timestamp (timestamp,mictime),
      INDEX (id),
      INDEX (timestamp)
      ) TYPE=MyISAM COMMENT='Sensor data'
      ", $db);
      echo mysql_error($db);
      echo "Neue Datentabelle wurde erstellt.<br>\n";
      echo "Die ersten Daten werden nach dem nächsten
        Datendownload vom Messrechner bereit stehen.<br>\n";
    }
    // Create shortcut on KDE desktop to connect
    $fp = fopen("/home/schtorch/KDesktop/Connect to
      $computer.desktop", "w+");
    if (!$fp) echo "Konnte Shortcut auf dem Desktop nicht
      anlegen";
    fwrite($fp, "
    [Desktop Entry]
    Comment[en_US]=
    Encoding=UTF-8
    Exec=/home/schtorch/diplom/pppconn.sh $phone $protocol
      $user $passwd
    Icon=
    MimeType=
    Name[en_US]=Connect to $computer
    Path=
    ServiceTypes=
    SwallowExec=
    SwallowTitle=
    Terminal=true
    TerminalOptions=
    Type=Application
    X-KDE-SubstituteUID=false
    X-KDE-Username=
    ");
    fclose($fp);
    echo "Das Profil wurde erfolgreich
      abgespeichert.<br>\n";
    echo "<br><a href=\"index.php4\">Hauptmenü</a>";
  } else {
    echo "Leider ist folgender Fehler aufgetreten:<br>\n";
    echo $errorstr;
  }
  mysql_close($db);
?>
<br>
<hr>
(c) 2002 Jens Bierkandt, entstanden im Rahmen meiner
  Diplomarbeit </center>
</body>
</html>



Jens Bierkandt