|
street ?>"> |
|
city ?>"> |
|
zip ?>"> |
|
state ?>"> |
id;
$db_result = mysql_query($db_query);
if (!$db_result) die ('Chyba SQL: ' . mysql_error() . " " .$db_query);
else {
$db_row = mysql_fetch_row($db_result);
$this->id = $db_row[0];
$this->street = $db_row[1];
$this->city = $db_row[2];
$this->zip = $db_row[3];
$this->state = $db_row[4];
}
}
public function data_insert() {
db_connect();
$db_query = "INSERT INTO c_address (" .
($this->id > 0? "pk_c_address, " : "").
"street, ".
"city, ".
"zip, ".
"state ".
") VALUES (".
($this->id > 0? "'" . $this->id . "', ": "").
"'". $this->street ."',".
"'". $this->city ."',".
"'". $this->zip ."',".
"'". $this->state ."')";
$db_result = mysql_query($db_query);
if (!$db_result) die ('Chyba SQL: ' . mysql_error() . " " .$db_query);
else $this->id = mysql_insert_id();
return true;
}
public function data_update() {
db_connect();
$db_query = "UPDATE c_address SET " .
"street='". $this->street . "', ".
"city='". $this->city . "', ".
"zip='". $this->zip . "', ".
"state='". $this->state . "' ".
"WHERE pk_c_address='". $this->id ."'";
$db_result = false;
if ($this->id > 0) $db_result = mysql_query($db_query);
if (!$db_result) die ('Chyba SQL: ' . mysql_error() . " " .$db_query);
return true;
}
public function data_delete() {
db_connect();
$db_query = "DELETE FROM c_address " .
"WHERE pk_c_address=". $this->id ;
$db_result = false;
if ($this->id > 0)
if (mysql_query($db_query)) {
$db_query = "DELETE FROM c_join_person_address " .
"WHERE fk_c_address=". $this->id ;
$db_result += mysql_query($db_query);
$db_query = "DELETE FROM c_join_company_address " .
"WHERE fk_c_address=". $this->id ;
$db_result += mysql_query($db_query);
}
if (!$db_result) die ('Chyba SQL: ' . mysql_error() . " " .$db_query);
return true;
}
public function print_list_person() {
db_connect();
$db_query = "SELECT ".
"pk_c_join_person_phone, ".
"pk_c_person, " .
"priority, ".
"note, " .
"name, " .
"surname " .
"FROM c_join_person_phone ".
"INNER JOIN c_person ON fk_c_person=pk_c_person " .
"WHERE fk_c_phone=" . $this->id . " " .
"ORDER BY surname";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " . $db_query);
else if (mysql_num_rows($db_result)>0) {
?>
id . " " .
"ORDER BY name";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " . $db_query);
else if (mysql_num_rows($db_result)>0) {
?>
id .",".
$p_id_person .")";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
return true;
}
public function data_insert_relation_company($p_id_company) {
db_connect();
$db_query = "INSERT INTO c_join_company_address (".
"fk_c_address, ".
"fk_c_company ".
") VALUES (" .
$this->id .",".
$p_id_company .")";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
return true;
}
}
/****************************************************************************************/
function print_list_address($p_link) {
db_connect();
$db_query = "SELECT ".
"c_address.pk_c_address, ".
"c_address.street, " .
"c_address.city, " .
"c_address.zip, " .
"c_address.state, " .
"c_person.pk_c_person, ".
"c_person.name, ".
"c_person.surname, ".
"c_join_person_address.note, ".
"c_company.pk_c_company, ".
"c_company.name, ".
"c_join_company_address.note ".
"FROM ".
"c_address ".
"LEFT JOIN c_join_person_address ON pk_c_address=c_join_person_address.fk_c_address ".
"LEFT JOIN c_person ON pk_c_person=fk_c_person ".
"LEFT JOIN c_join_company_address ON pk_c_address=c_join_company_address.fk_c_address ".
"LEFT JOIN c_company ON pk_c_company=fk_c_company ".
"GROUP BY pk_c_address ".
"ORDER BY c_address.city, c_address.street";
$db_result = mysql_query($db_query);
if (!$db_result) die ('Chyba SQL: ' . mysql_error() . " " . $db_query);
else if (mysql_num_rows($db_result)>0) {
?>