Source for file class.KONTAKTE.php

Documentation is available at class.KONTAKTE.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * Stellt die Verbindung zur Datenbank 'person' her.
  6.  *
  7.  * Stellt Methoden zum Zugriff auf eine Person zur Verfügung.
  8.  *
  9.  * @author Kay Koch
  10.  * @package src
  11.  * @since 20.12.04
  12.  * @subpackage foundation_tables
  13.  * @version 1.0
  14.  */
  15.  
  16. if (version_compare(PHP_VERSION'5')) {
  17.     die('This file was generated for PHP 5');
  18. }
  19.  
  20. /**
  21.  * Basisklasse aller Klassen mit Datenbankzugriff.
  22.  *
  23.  * stellt Methoden und Objekte zur Fehlermeldung und zum Datenbankzugriff zur
  24.  *
  25.  * @author Kay Koch
  26.  * @since 1.12.04
  27.  * @version 1.1
  28.  */
  29. require_once('src/foundation/tables/class.PARENTTABLES.php');
  30.  
  31. /**
  32.  * Interface für die Klassen zur Manipulation der Datenbanktabellen
  33.  *
  34.  * @author Kay Koch, <kay.koch@gmx.de>
  35.  */
  36. require_once('src/interfaces/interface.TABLEINTERFACE.php');
  37.  
  38. /* user defined includes */
  39. // section -64--88-122--2-1328c7a:100f136ad5a:-7ff0-includes begin
  40. // section -64--88-122--2-1328c7a:100f136ad5a:-7ff0-includes end
  41.  
  42. /* user defined constants */
  43. // section -64--88-122--2-1328c7a:100f136ad5a:-7ff0-constants begin
  44. // section -64--88-122--2-1328c7a:100f136ad5a:-7ff0-constants end
  45.  
  46. /**
  47.  * Stellt die Verbindung zur Datenbank 'person' her.
  48.  *
  49.  * Stellt Methoden zum Zugriff auf eine Person zur Verfügung.
  50.  *
  51.  * @access public
  52.  * @author Kay Koch
  53.  * @package src
  54.  * @since 20.12.04
  55.  * @subpackage foundation_tables
  56.  * @version 1.0
  57.  */
  58.         implements src_interfaces_TABLEINTERFACE
  59. {
  60.     // --- ATTRIBUTES ---
  61.  
  62.     
  63.     /**
  64.      * beinhaltet einen Datensatz der zuständigen Tabelle aus der Datenbank
  65.      *
  66.      * index ist die Kontakt_id
  67.      *
  68.      * @access private
  69.      * @since 21.12.04
  70.      * @var array 
  71.      */
  72.     private $data array();
  73.  
  74.     /**
  75.      * Beinhaltet den Datenbanknamen (maxfrei)
  76.      *
  77.      * @access protected
  78.      * @var string 
  79.      */
  80.     protected $dbTableName = 'kontakte';
  81.  
  82.     /**
  83.      * beinhaltet einen Datensatz der zuständigen Tabelle aus der Datenbank
  84.      *
  85.      * index ist der login
  86.      *
  87.      * @access private
  88.      * @var array 
  89.      */
  90.     private $dataLogin array();
  91.  
  92.     /**
  93.      * aktuelle Kontakt_id
  94.      *
  95.      * @access public
  96.      * @var int 
  97.      */
  98.     public $kontakt_id = 0;
  99.  
  100.     // --- OPERATIONS ---
  101.  
  102.     
  103.     /**
  104.      * liefert einen (mehrere) Datensatz die durch setzen per Parameter
  105.      * werden
  106.      *
  107.      * @access public
  108.      * @author Kay Koch, <kay.koch@gmx.de>
  109.      * @return array 
  110.      */
  111.     public function getRow()
  112.     {
  113.         $returnValue array();
  114.  
  115.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7fab begin
  116.         if (!empty($this->kontakt_id))
  117.             $returnValue $this->data[$this->kontakt_id];
  118.         else
  119.             $returnValue $this->data;
  120.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7fab end
  121.  
  122.         return (array) $returnValue;
  123.     }
  124.  
  125.     /**
  126.      * veranlasst ein Update
  127.      *
  128.      * @access public
  129.      * @author Kay Koch, <kay.koch@gmx.de>
  130.      * @param array 
  131.      * @return boolean 
  132.      */
  133.     public function updateRow($data)
  134.     {
  135.         $returnValue = (bool) false;
  136.  
  137.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7fa9 begin
  138.         try {
  139.             $sql "UPDATE  IGNORE $this->dbTableName
  140.                     SET name = '$data['name'"',
  141.                         vorname = '" $data['vorname'"',
  142.                         login = '" $data['login'"',
  143.                         telefon = '" $data['telefon'"',
  144.                         fax = '" $data['fax'"',
  145.                         mobil = '" $data['mobil'"',
  146.                         email = '" $data['email'"',
  147.                         isAdmin = '" $data['isAdmin'"'
  148.                     WHERE kontakt_ID = '$this->kontakt_id";
  149.             if (!$this->update($sql))
  150.                 throw new Exception ();
  151.             $this->updateData();
  152.             $returnValue true;
  153.         }
  154.         catch (Exception $e{
  155.         }
  156.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7fa9 end
  157.  
  158.         return (bool) $returnValue;
  159.     }
  160.  
  161.     /**
  162.      * fügt einen neuen Datensatz ein
  163.      *
  164.      * @access public
  165.      * @author Kay Koch, <kay.koch@gmx.de>
  166.      * @param array 
  167.      * @return boolean 
  168.      */
  169.     public function insertRow($data)
  170.     {
  171.         $returnValue = (bool) false;
  172.  
  173.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7fa6 begin
  174.         try {
  175.             $sql "INSERT IGNORE INTO $this->dbTableName
  176.                     SET name = '$data['name'"',
  177.                         vorname = '" $data['vorname'"',
  178.                         login = '" $data['login'"',
  179.                         pwd = '" md5('12345')"',
  180.                         telefon = '" $data['telefon'"',
  181.                         fax = '" $data['fax'"',
  182.                         mobil = '" $data['mobil'"',
  183.                         email = '" $data['email'"',
  184.                         isAdmin = '" $data['isAdmin'"'";
  185.             if (!$this->insert($sql))
  186.                 throw new Exception ();
  187.             $this->updateData();
  188.             $returnValue true;
  189.         }
  190.         catch (Exception $e{
  191.         }
  192.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7fa6 end
  193.  
  194.         return (bool) $returnValue;
  195.     }
  196.  
  197.     /**
  198.      * löscht einen Datensatz
  199.      *
  200.      * @access public
  201.      * @author Kay Koch, <kay.koch@gmx.de>
  202.      * @return boolean 
  203.      */
  204.     public function deleteRow()
  205.     {
  206.         $returnValue = (bool) false;
  207.  
  208.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7f9e begin
  209.         try {
  210.             $sql "DELETE FROM $this->dbTableName WHERE kontakt_ID = '$this->kontakt_id";
  211.             if (!$this->delete($sql))
  212.                 throw new Exception ();
  213.             $this->updateData();
  214.             $returnValue true;
  215.         }
  216.         catch (Exception $e{;
  217.         }
  218.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7f9e end
  219.  
  220.         return (bool) $returnValue;
  221.     }
  222.  
  223.     /**
  224.      * aktualisiert die Daten im gegenwertigen Objekt
  225.      *
  226.      * @access public
  227.      * @author Kay Koch, <kay.koch@gmx.de>
  228.      * @return boolean 
  229.      */
  230.     public function updateData()
  231.     {
  232.         $returnValue = (bool) false;
  233.  
  234.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7f9c begin
  235.         $sql "SELECT * FROM  $this->dbTableName ORDER by name,vorname ASC";
  236.         $arrKontakte $this->select($sqltrue"kontakt_id");
  237.         foreach ($arrKontakte as $kontakt_id=>$arrKontakt)
  238.             $this->data[$kontakt_idnew src_foundation_datatypes_EINKONTAKT ($arrKontakt);
  239.         parent:: setKontakte($this);
  240.         $this->dataLogin $this->select($sqltrue"login");
  241.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7f9c end
  242.  
  243.         return (bool) $returnValue;
  244.     }
  245.  
  246.     /**
  247.      * löscht die Parameter, die den gegenwärtigen Datensatz identifizieren
  248.      *
  249.      * @access public
  250.      * @author Kay Koch, <kay.koch@gmx.de>
  251.      * @return void 
  252.      */
  253.     public function unsetParams()
  254.     {
  255.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7f97 begin
  256.         unset($this->kontakt_id);
  257.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7f97 end
  258.     }
  259.  
  260.     /**
  261.      * überprüft ob ein Kontakt Administratorrechte besitzt
  262.      *
  263.      * @access public
  264.      * @author Kay Koch, <kay.koch@gmx.de>
  265.      * @param string 
  266.      * @param string 
  267.      * @return boolean 
  268.      */
  269.     public function isAdmin($login$pwd)
  270.     {
  271.         $returnValue = (bool) false;
  272.  
  273.         // section -64--88-122--2--759b93b2:10397a7591b:-7fe3 begin
  274.         try {
  275.             if (empty ($loginOR empty ($pwd))
  276.                 throw new Exception("");
  277.             if (!isset($this->dataLogin[$login]))
  278.                 throw new Exception("");
  279.             if (!$this->dataLogin[$login]['isAdmin'or $this->dataLogin[$login]['pwd'!= md5($pwd))
  280.                 throw new Exception("");
  281.             $returnValue true;
  282.         }
  283.         catch (Exception $e{;
  284.         }
  285.         // section -64--88-122--2--759b93b2:10397a7591b:-7fe3 end
  286.  
  287.         return (bool) $returnValue;
  288.     }
  289.  
  290.     /**
  291.      * ändert das Passwort
  292.      *
  293.      * @access public
  294.      * @author Kay Koch, <kay.koch@gmx.de>
  295.      * @param string 
  296.      * @param string 
  297.      * @param string 
  298.      * @return boolean 
  299.      */
  300.     public function setPWD($login$pwd$newPWD)
  301.     {
  302.         $returnValue = (bool) false;
  303.  
  304.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fad begin
  305.         try {
  306.             $pwd md5($pwd)// altes Passwort verschlüsseln;
  307.             if (!isset($this->dataLogin[$login]))
  308.                 throw new Exception("1");
  309.             if ($this->dataLogin[$login]['pwd'!= $pwd )
  310.                 throw new Exception("2");
  311.             $sql "UPDATE $this->dbTableName SET pwd=md5('$newPWD') WHERE login='$loginAND pwd='$pwd";
  312.             if (!$this->update($sql))
  313.                 throw new Exception("3");
  314.             $returnValue true;
  315.         }
  316.         catch (Exception $e{
  317.         }
  318.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fad end
  319.  
  320.         return (bool) $returnValue;
  321.     }
  322.  
  323.     /**
  324.      * setzt die Daten für die aktuelle Bearbeitung
  325.      *
  326.      * @access public
  327.      * @author Kay Koch, <kay.koch@gmx.de>
  328.      * @param int 
  329.      * @return void 
  330.      */
  331.     public function setParams($kontakt_id)
  332.     {
  333.         // section -64--88-122--2-339007d5:1043cd4e8c9:-7f98 begin
  334.         $this->kontakt_id = $kontakt_id;
  335.         // section -64--88-122--2-339007d5:1043cd4e8c9:-7f98 end
  336.     }
  337.  
  338.     /**
  339.      * liefert eine Optionslist mit allen Kontakten
  340.      *
  341.      * @access public
  342.      * @author Kay Koch, <kay.koch@gmx.de>
  343.      * @param string 
  344.      * @return string 
  345.      */
  346.     public function getOptionList($index '')
  347.     {
  348.         $returnValue = (string) '';
  349.         // section -64--88-122--2-339007d5:1043cd4e8c9:-7f95 begin
  350.         foreach($this->data as $oEinKontakt{
  351.             $selected ($oEinKontakt->kontakt_id == $index"SELECTED" "";
  352.             $returnValue .= "<option $selected value='$oEinKontakt->kontakt_id "'>" $oEinKontakt->name ", " $oEinKontakt->vorname "</option>\n";
  353.         }
  354.         // section -64--88-122--2-339007d5:1043cd4e8c9:-7f95 end
  355.  
  356.         return (string) $returnValue;
  357.     }
  358.  
  359.     /**
  360.      * Konstruktor
  361.      *
  362.      * lädt alle Kontakte
  363.      *
  364.      * @access public
  365.      * @author Kay Koch, <kay.koch@gmx.de>
  366.      * @return void 
  367.      */
  368.     public function __construct()
  369.     {
  370.         // section -64--88-122--2-7471698e:1046ab3b89c:-7feb begin
  371.         parent::__construct();
  372.         if (empty($this->data))
  373.             $this->updateData();
  374.         // section -64--88-122--2-7471698e:1046ab3b89c:-7feb end
  375.     }
  376.  
  377.     /**
  378.      * liefert den Inhalt eines Feldes mit Namen Index aus den Kontakten
  379.      *
  380.      * @access public
  381.      * @author Kay Koch, <kay.koch@gmx.de>
  382.      * @param string 
  383.      * @return string 
  384.      */
  385.     private function __get ($index)
  386.     {
  387.         $returnValue = (string) '';
  388.         //
  389.         try {
  390.             if (empty ($index))
  391.                 throw new Exception(4);
  392.             if ($index=="all")
  393.                 $returnValue $this->data;
  394.             if (isset ($this->data[$index]))
  395.                 $returnValue $this->data[$index];
  396.         }
  397.         catch (Exception $e{
  398.             src_tools_ERROR::setError($e__METHOD__);
  399.         }
  400.           //
  401.         return ($returnValue);
  402.     }
  403.  
  404. /* end of class src_foundation_tables_KONTAKTE*/
  405.  
  406. ?>

Documentation generated on Sat, 24 Mar 2007 09:59:35 +0100 by phpDocumentor 1.3.1