function buildQuickForm()
 {
     // first: sort out the contacts
     $contacts = array();
     $households = array();
     $organisations = array();
     foreach ($this->_contactIds as $contact_id) {
         $contact = civicrm_api3('Contact', 'getsingle', array('id' => $contact_id));
         if ($contact['contact_type'] == 'Individual') {
             $contacts[$contact_id] = $contact;
         } elseif ($contact['contact_type'] == 'Household') {
             $households[$contact_id] = $contact;
         } else {
             $organisations[$contact_id] = $contact;
         }
     }
     $this->assign('contacts', $contacts);
     $this->assign('households', $households);
     $this->assign('ignored', $organisations);
     $patterns = $this->calculatePatterns($contacts);
     $patterns['custom'] = ts("Custom Name", array('domain' => 'de.systopia.householdmerge'));
     // adjust title
     CRM_Utils_System::setTitle(ts("Merge %1 contacts into a Household", array(1 => count($contacts), 'domain' => 'de.systopia.householdmerge')));
     // Add switch and ID list
     $this->add('hidden', 'hh_option');
     $this->add('hidden', 'hh_contacts', implode(',', array_keys($contacts)));
     // Add "CREATE NEW" elements
     $this->add('text', 'household_name', ts('Household Name', array('domain' => 'de.systopia.householdmerge')), array('size' => 32, 'placeholder' => ts("Enter household name", array('domain' => 'de.systopia.householdmerge'))), FALSE);
     $pattern_select = $this->add('select', 'household_name_pattern', ts('Household Name', array('domain' => 'de.systopia.householdmerge')), $patterns, TRUE);
     $pattern_select->setSelected('custom');
     // Add "MERGE INTO" elements
     $this->add('text', 'existing_household', ts('Enter Household ID', array('domain' => 'de.systopia.householdmerge')), array('size' => 5), false);
     $this->addButtons(array(array('type' => 'submit', 'name' => ts('Merge', array('domain' => 'de.systopia.householdmerge')), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Abort', array('domain' => 'de.systopia.householdmerge')), 'isDefault' => FALSE)));
     parent::buildQuickForm();
 }
 function buildQuickForm()
 {
     $mysql = 'SELECT id FROM veda_civicrm_wordmailmerge';
     $tableCount = CRM_Core_DAO::executeQuery($mysql);
     $noofRows = array();
     while ($tableCount->fetch()) {
         $noofRows = $tableCount->id;
     }
     $rowCount = count($noofRows);
     if ($rowCount == 0) {
         $this->add('select', 'message_template', ts('Message Template'), array('' => '- select -'), TRUE);
         CRM_Core_Session::setStatus(ts("No attachement in the template."));
     } else {
         $sql = " SELECT cmt.id, cmt.msg_title FROM civicrm_msg_template cmt\n               RIGHT JOIN veda_civicrm_wordmailmerge vcw ON ( vcw.msg_template_id = cmt.id)";
         $dao = CRM_Core_DAO::executeQuery($sql);
         while ($dao->fetch()) {
             $msgTemplatesResult[$dao->id] = $dao->msg_title;
         }
         // add form elements
         $this->add('select', 'message_template', ts('Message Template'), array('' => '- select -') + $msgTemplatesResult, TRUE);
         // if mergeSameAddress method exists
         if (method_exists('CRM_Core_BAO_Address', 'mergeSameAddress')) {
             //add checkbox for merge contacts with same address
             $this->add('checkbox', 'merge_letter_for_same_address', ts('Merge letter for same address'), NULL);
         }
         $this->addButtons(array(array('type' => 'submit', 'name' => ts('Merge'), 'isDefault' => TRUE)));
     }
     // export form elements
     $this->assign('elementNames', $this->getRenderableElementNames());
     parent::buildQuickForm();
 }