First fix of PHP 8.2 deprecated errors. Not seen with $go_debug = 0, but error.log...
[fa-stable.git] / includes / ui / contacts_view.inc
index 9ad82aec4c0224e5f9bacde9522b7f4ec7fc0fd3..82c06342d168ea39689408aa1260d7c32a170d37 100644 (file)
@@ -21,51 +21,59 @@ class contacts extends simple_crud {
        var $sub_class;
        var $class;
        
-       function contacts($name, $id, $class, $subclass=null) {
+       function __construct($name, $id, $class, $subclass=null) {
                $fields = array('ref','name','name2','address', 'phone', 'phone2','fax',
                        'email','lang','notes', 'assgn' =>array('fld'=>'contacts'));
 
-               $this->simple_crud($name, $fields);
+               parent::__construct($name, $fields);
                $this->class = $class;
-               $this->subclass = $subclass;
+               $this->sub_class = $subclass;
                $this->entity = $id;
        }
 
        function list_view() {
                br();
 
-                       $contacts = get_crm_persons($this->class, $this->subclass, $this->entity);
-//                             check_value('show_inactive'));
-                       start_table(TABLESTYLE, "width=80%");
+                       $contacts = get_crm_persons($this->class, $this->sub_class, $this->entity);
+                       start_table(TABLESTYLE, "width='80%'");
 
                        $th = array(_('Assignment'), _("Reference"), _("Full Name"), _("Phone"), _("Sec Phone"), _("Fax"),
                                _("email"),  '',
                                " ");
-               //      inactive_control_column($th);
 
                        table_header($th);
                        $k = 0; 
-                       while ($myrow = db_fetch($contacts)) 
+
+                       $last = $myrow = db_fetch($contacts);
+                       while ($last)
                        {
-                               alt_table_row_color($k);
-                               label_cell($myrow["description"]);
-                               label_cell($myrow["ref"]);
-                               label_cell($myrow["name"].' '.$myrow["name2"]);
-                               label_cell($myrow["phone"]);
-                               label_cell($myrow["phone2"]);
-                               label_cell($myrow["fax"]);
-                               email_cell($myrow["email"]);
-
-               //      inactive_control_cell($myrow["id"], $myrow["inactive"], 'crm_contacts', 'id');
-
-                               edit_button_cell("{$this->name}Edit[{$myrow['id']}]", _("Edit"));
-
-                       // delete button removes only category unless this is the last contact for this person
-                               delete_button_cell("{$this->name}Delete[{$myrow['contact_id']}]", _("Delete"));
-                               end_row();
+                                       
+                               if (@$myrow['id'] != $last['id']) {
+                                       alt_table_row_color($k);
+                                       label_cell(implode('<br>',$description));
+                                       label_cell($last["ref"]);
+                                       label_cell($last["name"].' '.$last["name2"]);
+                                       label_cell($last["phone"]);
+                                       label_cell($last["phone2"]);
+                                       label_cell($last["fax"]);
+                                       email_cell($last["email"]);
+
+                                       edit_button_cell("{$this->name}Edit[{$last['id']}]", _("Edit"));
+
+                                       // delete button removes only category unless this is the last contact for this person
+                                       delete_button_cell("{$this->name}Delete[{$last['id']}]", _("Delete"));
+                                       end_row();
+                                       $description = array();
+                                       $last = $myrow;
+                               }
+
+                               if ($myrow) {
+                                       $description[] = $myrow['description'];
+                                       $myrow = db_fetch($contacts);
+                               }
                        }
-       
-//inactive_control_row($th);
+
+                       //inactive_control_row($th);
                        end_table(1);
        }
        
@@ -73,7 +81,7 @@ class contacts extends simple_crud {
        {
                br();
 
-               start_outer_table(TABLESTYLE, "width=80%");
+               start_outer_table(TABLESTYLE);
 
                table_section(1);
                table_section_title(_("Contact data"));
@@ -83,7 +91,7 @@ class contacts extends simple_crud {
                text_row(_("Reference:"), 'ref', @$this->data['ref'], 35, 40);
 
                crm_category_types_list_row(_("Contact active for:"), 'assgn', @$this->data['contacts'],
-                       array('subclass' => @$this->subclass,
+                       array('subclass' => @$this->sub_class,
                                'class' => @$this->class, 
                                'multi' =>true)
                                );
@@ -94,6 +102,7 @@ class contacts extends simple_crud {
                email_row(_("E-mail:"), 'email', @$this->data['email'], 35, 55);
 
                table_section(2);
+               table_section_title("&nbsp;");
                textarea_row(_("Address:"), 'address', @$this->data['address'], 30, 4);
                languages_list_row( _("Document Language:"), 'lang', @$this->data['lang'], _("Customer default"));
 
@@ -111,8 +120,7 @@ class contacts extends simple_crud {
        function db_update() {
                        return update_crm_person($this->selected_id, $_POST['ref'], $_POST['name'], $_POST['name2'], 
                                $_POST['address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], 
-                               $_POST['lang'], $_POST['notes'], $_POST['assgn'], $this->entity);
-               
+                               $_POST['lang'], $_POST['notes'], $_POST['assgn'], $this->entity, $this->class);
        }
 
        function insert_check() {
@@ -126,7 +134,7 @@ class contacts extends simple_crud {
                        set_focus('ref');
                        return false;
                }
-               if (count(@$_POST['assgn']) == 0) {
+               if (count_array(@$_POST['assgn']) == 0) {
                        display_error(_("You have to select at least one category."));
                        set_focus('assgn');
                        return false;
@@ -142,19 +150,17 @@ class contacts extends simple_crud {
                return true;
        }
        //
-       //      Delete single contact only (unless this is last contact for this person)
+       //      Delete all contacts for person in current class/entity
        //
        function db_delete() {
-               $rel = get_crm_contact($this->selected_id);
-               if (delete_crm_contact($this->selected_id)) {
+               if (delete_crm_contacts($this->selected_id, $this->class, $this->entity)) {
                        // if this is the last relation - delete contact data
-                       $rels = get_person_contacts($rel['person_id']);
+                       $rels = get_person_contacts($this->selected_id);
                        if (count($rels)==0) {
-                               return delete_crm_person($rel['person_id']);
+                               return delete_crm_person($this->selected_id);
                        }
                }
                return false;
        }
 }
 
-?>
\ No newline at end of file