type = new webt_company_type();
} /* }}} */
public function print_form() { /* {{{ *************************************/
?>
|
name ?> |
|
type->name ?> |
|
idn ?> |
|
txn ?> |
name . " " . $this->type->name;
} /* }}} */
/* DATA HANDLING {{{ **********************************************************/
public function data_get() { /* {{{ ****************************************/
db_connect();
$db_query = "SELECT ".
"pk_c_company, ".
"c_company.name, " .
"idn, " .
"txn, " .
"pk_c_company_type, " .
"c_company_type.name " .
"FROM c_company " .
"INNER JOIN c_company_type ON pk_c_company_type=fk_c_company_type " .
"WHERE pk_c_company=" . $this->id;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " . $db_query);
else {
$db_row = mysql_fetch_row($db_result);
$this->id = $db_row[0];
$this->name = $db_row[1];
$this->idn = $db_row[2];
$this->txn = $db_row[3];
$this->type->id = $db_row[4];
$this->type->name = $db_row[5];
}
} /* }}} */
public function data_insert() { /* {{{ *************************************/
db_connect();
$db_query = "INSERT INTO c_company (" .
($this->id > 0? "pk_c_company, " : "").
"name, ".
"idn, ".
"txn, ".
"fk_c_company_type ".
") VALUES (".
($this->id > 0? "'" . $this->id . "', ": "").
"'". $this->name . "', ".
"'". $this->idn . "', ".
"'". $this->txn . "', ".
"'". $this->type->id . "')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
else $this->id = mysql_insert_id();
return true;
} /* }}} */
public function data_update() { /* {{{ ************************************/
db_connect();
$db_query = "UPDATE c_company SET " .
"name='". $this->name . "', ".
"idn='". $this->idn . "', ".
"txn='". $this->txn . "', ".
"fk_c_company_type='". $this->type->id . "' ".
"WHERE pk_c_company='". $this->id ."'";
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_company " .
"WHERE pk_c_company='". $this->id ."'";
$db_result = false;
if ($this->id > 0) $db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
return true;
} /* }}} */
/* }}} ************************************************************************/
/* RELATION DEPARTMENT {{{ ****************************************************/
public function print_list_department_person() { /* {{{ ********************/
$l_department=new webt_company_department();
$l_department->id = 0;
$l_department->name = "";
$l_department->id_company = $this->id;
$l_department->print_list_person();
db_connect();
$db_query = "SELECT ".
"pk_c_department, ".
"name " .
"FROM c_department ".
"WHERE fk_c_company=" . $this->id;
$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) {
while ($db_row = mysql_fetch_row($db_result)) {
$l_department=new webt_company_department();
$l_department->id = $db_row[0];
$l_department->name = $db_row[1];
$l_department->id_company = $this->id;
$l_department->print_list_person();
}
}
} /* }}} */
public function edit_list_department() { /* {{{ ****************************/
db_connect();
$db_query = "SELECT ".
"pk_c_department, ".
"name " .
"FROM c_department ".
"WHERE fk_c_company=" . $this->id;
$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 . "', ".
"'". $p_id_department . "', ".
"'". $p_note . "')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
return true;
} /* }}} */
/* }}} ************************************************************************/
/* RELATION PHONE {{{ *********************************************************/
public function data_insert_phone($p_number, $p_note, $p_priority) { /*{{{*/
db_connect();
$db_query = "INSERT INTO c_phone (number) VALUES ('". $p_number ."')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
else {
$l_id_phone = mysql_insert_id();
$db_query = "INSERT INTO c_join_company_phone (".
"fk_c_company, ".
"fk_c_phone, ".
"priority,".
"note) ".
"VALUES (".
"'". $this->id ."',".
"'". $l_id_phone ."',".
"'". $p_priority ."',".
"'". $p_note ."')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
}
return true;
} /* }}} */
public function print_list_phone() { /* {{{ *******************************/
db_connect();
$db_query = "SELECT ".
"priority, ".
"note, " .
"number " .
"FROM c_phone ".
"INNER JOIN c_join_company_phone ON pk_c_phone=fk_c_phone " .
"WHERE fk_c_company=" . $this->id . " " .
"ORDER BY priority";
$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 priority";
$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;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
}
$db_query = "UPDATE c_join_company_phone SET " .
"note='". $p_note . "', ".
"priority='". $p_priority . "' ".
"WHERE pk_c_join_company_phone=". $p_id_join_phone;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
return true;
} /* }}} */
/* }}} ************************************************************************/
/* RELATION EMAIL {{{ *********************************************************/
public function data_insert_email($p_email, $p_note, $p_priority) { /* {{{*/
db_connect();
$db_query = "INSERT INTO c_email (url) VALUES ('". $p_email ."')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
else {
$l_id_email = mysql_insert_id();
$db_query = "INSERT INTO c_join_company_email (".
"fk_c_company, ".
"fk_c_email, ".
"priority,".
"note) ".
"VALUES (".
"'". $this->id ."',".
"'". $l_id_email ."',".
"'". $p_priority ."',".
"'". $p_note ."')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
}
return true;
} /* }}} */
public function print_list_email() { /* {{{ *******************************/
db_connect();
$db_query = "SELECT ".
"priority, ".
"note, " .
"url " .
"FROM c_email ".
"INNER JOIN c_join_company_email ON pk_c_email=fk_c_email " .
"WHERE fk_c_company=" . $this->id . " " .
"ORDER BY priority";
$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 priority";
$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;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
}
$db_query = "UPDATE c_join_company_email SET " .
"note='". $p_note . "', ".
"priority='". $p_priority . "' ".
"WHERE pk_c_join_company_email=". $p_id_join_email;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
return true;
} /* }}} */
/* }}} ************************************************************************/
/* RELATION WEB {{{ ***********************************************************/
public function data_insert_web($p_web, $p_note, $p_priority) { /* {{{ */
db_connect();
$db_query = "INSERT INTO c_web (url) VALUES ('". $p_web ."')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
else {
$l_id_web = mysql_insert_id();
$db_query = "INSERT INTO c_join_company_web (".
"fk_c_company, ".
"fk_c_web, ".
"priority,".
"note) ".
"VALUES (".
"'". $this->id ."',".
"'". $l_id_web ."',".
"'". $p_priority ."',".
"'". $p_note ."')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
}
return true;
} /* }}} */
public function print_list_web() { /* {{{ *********************************/
db_connect();
$db_query = "SELECT ".
"priority, ".
"note, " .
"url " .
"FROM c_web ".
"INNER JOIN c_join_company_web ON pk_c_web=fk_c_web " .
"WHERE fk_c_company=" . $this->id . " " .
"ORDER BY priority";
$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 priority";
$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;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
}
$db_query = "UPDATE c_join_company_web SET " .
"note='". $p_note . "', ".
"priority='". $p_priority . "' ".
"WHERE pk_c_join_company_web=". $p_id_join_web;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
return true;
} /* }}} */
/* }}} ************************************************************************/
/* RELATION ADDRESS {{{ *******************************************************/
public function data_insert_address($p_street,$p_city,$p_zip,$p_state, $p_note, $p_priority) { /*{{{*/
db_connect();
$db_query = "INSERT INTO c_address (" .
"street, ".
"city, ".
"zip, ".
"state ".
") VALUES (".
"'". $p_street . "', ".
"'". $p_city . "', ".
"'". $p_zip . "', ".
"'". $p_state . "')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
else {
$l_id_address = mysql_insert_id();
$db_query = "INSERT INTO c_join_company_address (".
"fk_c_company, ".
"fk_c_address, ".
"priority,".
"note) ".
"VALUES (".
"'". $this->id ."',".
"'". $l_id_address ."',".
"'". $p_priority ."',".
"'". $p_note ."')";
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
}
return true;
} /* }}} */
public function print_list_address() { /* {{{ *****************************/
db_connect();
$db_query = "SELECT ".
"priority, ".
"note, " .
"street, " .
"city, " .
"zip, " .
"state ".
"FROM c_address ".
"INNER JOIN c_join_company_address ON pk_c_address=fk_c_address " .
"WHERE fk_c_company=" . $this->id . " " .
"ORDER BY priority";
$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 priority";
$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;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
}
$db_query = "UPDATE c_join_company_address SET " .
"note='". $p_note . "', ".
"priority='". $p_priority . "' ".
"WHERE pk_c_join_company_address=". $p_id_join_web;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
return true;
} /* }}} */
/* }}} ************************************************************************/
} /* }}} **********************************************************************/
class webt_company_type { /* {{{ **********************************************/
public $id;
public $name;
public function print_list() { /* {{{ *************************************/
db_connect();
?>
id_company . "', ".
"'". $this->name . "')";
$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_delete() { /* {{{ ***************************************/
db_connect();
$db_query = "DELETE FROM c_department WHERE pk_c_department=". $this->id;
$db_result = mysql_query($db_query);
if (!$db_result) die (MSG_ERROR_SQL . mysql_error() . " " .$db_query);
return true;
} /* }}} */
public function data_count() { /* {{{ *************************************/
db_connect();
$db_query = "SELECT * FROM c_department ".
"WHERE fk_c_company=". $this->id_company;
$db_result = mysql_query($db_query);
return mysql_num_rows($db_result);
} /* }}} */
public function print_list_person() { /* {{{ ******************************/
db_connect();
$db_query = "SELECT ".
"c_person.pk_c_person, ".
"c_person.name, " .
"c_person.surname, ".
"c_person.title_preffix, ".
"c_person.title_suffix, ".
"c_phone.number, ".
"c_email.url, ".
"c_web.url ".
"FROM ".
"c_person ".
"INNER JOIN c_join_employ ON pk_c_person=c_join_employ.fk_c_person ".
"LEFT JOIN c_join_person_phone ON pk_c_person=c_join_person_phone.fk_c_person ".
"LEFT JOIN c_phone ON pk_c_phone=fk_c_phone ".
"LEFT JOIN c_join_person_email ON pk_c_person=c_join_person_email.fk_c_person ".
"LEFT JOIN c_email ON pk_c_email=fk_c_email ".
"LEFT JOIN c_join_person_web ON pk_c_person=c_join_person_web.fk_c_person ".
"LEFT JOIN c_web ON pk_c_web=fk_c_web ".
"WHERE ".
"c_join_employ.fk_c_company=" . $this->id_company . " AND ".
"c_join_employ.fk_c_department=" . $this->id . " ".
"GROUP BY pk_c_person ".
"ORDER BY c_person.surname,c_person.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) {
?>