}
         foreach ($invoice_data_parts['values'] as $index => $value) {
             $invoice_data_parts['values'][$index] = trim($value);
         }
         $invoice_data_parts['keys'][] = "(days_overdue)";
         $invoice_data_parts['values'][] = trim($days_overdue);
         //create email message
         $email_message = @security_form_input_predefined("any", "email_message", 0, "");
         $email_message = str_replace($invoice_data_parts['keys'], $invoice_data_parts['values'], $email_message);
         //create subject
         $subject = @security_form_input_predefined("any", "subject", 0, "");
         $subject = str_replace($invoice_data_parts['keys'], $invoice_data_parts['values'], $subject);
         //sender
         $from = @security_form_input_predefined("any", "sender", 0, "");
         if ($from == "user") {
             $from = user_information("contact_email");
         } else {
             $from = sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_CONTACT_EMAIL'");
         }
         log_debug("EMAIL", "avout to send" . $i);
         // send email
         $obj_invoice->email_invoice($from, $to, "", "", $subject, $email_message);
         $_SESSION["notification"]["message"][] = "Reminder email for Invoice " . $obj_sql_invoice->data[0]["code_invoice"] . " was sent successfully.";
     }
 }
 //set error messages for emails that couldn't be sent
 for ($i = 0; $i < count($error_array); $i++) {
     $_SESSION["error"]["message"][] = "Reminder for Invoice " . $error_array[$i] . " was not sent as no email is set for the customer's default account.";
 }
 header("Location: ../../index.php?page=accounts/ar/account-statements.php");
 exit(0);
 function execute()
 {
     log_debug("invoice_form_export", "Executing execute()");
     /*
     	Fetch basic invoice details
     */
     $obj_sql_invoice = new sql_query();
     if ($this->type == "ar") {
         $obj_sql_invoice->string = "SELECT code_invoice, customerid FROM account_" . $this->type . " WHERE id='" . $this->invoiceid . "' LIMIT 1";
     } else {
         $obj_sql_invoice->string = "SELECT code_quote, customerid FROM account_" . $this->type . " WHERE id='" . $this->invoiceid . "' LIMIT 1";
     }
     $obj_sql_invoice->execute();
     $obj_sql_invoice->fetch_array();
     /*
     	Generate Email
     
     	This function call provides us with all the email fields we can use to complete the form with.
     */
     $obj_invoice = new invoice();
     $obj_invoice->type = $this->type;
     $obj_invoice->id = $this->invoiceid;
     $email = $obj_invoice->generate_email();
     /*
     	Define email form
     */
     $this->obj_form_email = new form_input();
     $this->obj_form_email->formname = "invoice_export_email";
     $this->obj_form_email->language = $_SESSION["user"]["lang"];
     $this->obj_form_email->action = $this->processpage;
     $this->obj_form_email->method = "post";
     // general
     $structure = NULL;
     $structure["fieldname"] = "sender";
     $structure["type"] = "radio";
     $structure["defaultvalue"] = $email["sender"];
     $structure["values"] = array("system", "user");
     $structure["translations"]["system"] = sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_NAME'") . " &lt;" . sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_CONTACT_EMAIL'") . "&gt;";
     $structure["translations"]["user"] = user_information("realname") . " &lt;" . user_information("contact_email") . "&gt;";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "subject";
     $structure["type"] = "input";
     $structure["defaultvalue"] = $email["subject"];
     $structure["options"]["width"] = "600";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "email_to";
     $structure["type"] = "input";
     $structure["defaultvalue"] = $email["to"];
     $structure["options"]["width"] = "600";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "email_cc";
     $structure["type"] = "input";
     $structure["defaultvalue"] = $email["cc"];
     $structure["options"]["width"] = "600";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "email_bcc";
     $structure["type"] = "input";
     $structure["defaultvalue"] = $email["bcc"];
     $structure["options"]["width"] = "600";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "email_message";
     $structure["type"] = "textarea";
     $structure["defaultvalue"] = $email["message"];
     $structure["options"]["width"] = "600";
     $structure["options"]["height"] = "100";
     $this->obj_form_email->add_input($structure);
     // hidden
     $structure = NULL;
     $structure["fieldname"] = "formname";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->obj_form_email->formname;
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "id_invoice";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->invoiceid;
     $this->obj_form_email->add_input($structure);
     // submit button
     $structure = NULL;
     $structure["fieldname"] = "submit";
     $structure["type"] = "submit";
     $structure["defaultvalue"] = "Send via Email";
     $this->obj_form_email->add_input($structure);
     // load any data returned due to errors
     $this->obj_form_email->load_data_error();
     /*
     	Define download form
     */
     $this->obj_form_download = new form_input();
     $this->obj_form_download->formname = "invoice_export_download";
     $this->obj_form_download->language = $_SESSION["user"]["lang"];
     $this->obj_form_download->action = $this->processpage;
     $this->obj_form_download->method = "post";
     // general
     $structure = NULL;
     $structure["fieldname"] = "invoice_mark_as_sent";
     $structure["type"] = "checkbox";
     $structure["options"]["label"] = "Check this to show that the invoice has been sent to the customer when you download the PDF";
     $this->obj_form_download->add_input($structure);
     // hidden
     $structure = NULL;
     $structure["fieldname"] = "formname";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->obj_form_download->formname;
     $this->obj_form_download->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "id_invoice";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->invoiceid;
     $this->obj_form_download->add_input($structure);
     // submit button
     $structure = NULL;
     $structure["fieldname"] = "submit";
     $structure["type"] = "submit";
     $structure["defaultvalue"] = "Download as PDF";
     $this->obj_form_download->add_input($structure);
     // load any data returned due to errors
     $this->obj_form_download->load_data_error();
     return 1;
 }
 function email_credit($email_sender, $email_to, $email_cc, $email_bcc, $email_subject, $email_message)
 {
     log_debug("inc_credits", "Executing email_credit([options])");
     // external dependency of Mail_Mime
     if (!@(include_once 'Mail.php')) {
         log_write("error", "inc_credits", "Unable to find Mail module required for sending email");
         return 0;
     }
     if (!@(include_once 'Mail/mime.php')) {
         log_write("error", "inc_credits", "Unable to find Mail::Mime module required for sending email");
         return 0;
     }
     /*
     	Generate a PDF of the credit note and save to tmp file
     */
     log_debug("inc_credits", "Generating credit note PDF for emailing");
     // generate PDF
     $this->generate_pdf();
     if (error_check()) {
         return 0;
     }
     // save to a temporary file
     $tmp_filename = file_generate_name("/tmp/credit_" . $this->data["code_credit"] . "", "pdf");
     if (!($fhandle = fopen($tmp_filename, "w"))) {
         die("fatal error occured whilst writing to file {$tmp_filename}");
     }
     fwrite($fhandle, $this->obj_pdf->output);
     fclose($fhandle);
     /*
     	Email the credit note
     */
     log_debug("inc_credits", "Sending email");
     // fetch sender address
     //
     // users have the choice of sending as the company or as their own staff email address & name.
     //
     if ($email_sender == "user") {
         // send as the user
         $email_sender = "\"" . user_information("realname") . "\" <" . user_information("contact_email") . ">";
     } else {
         // send as the system
         $email_sender = "\"" . sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_NAME'") . "\" <" . sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_CONTACT_EMAIL'") . ">";
     }
     // prepare headers
     $mail_headers = array('From' => $email_sender, 'Subject' => $email_subject, 'Cc' => $email_cc, 'Bcc' => $email_bcc);
     $mail_mime = new Mail_mime("\n");
     $mail_mime->setTXTBody($email_message);
     $mail_mime->addAttachment($tmp_filename, 'application/pdf');
     $mail_body = $mail_mime->get();
     $mail_headers = $mail_mime->headers($mail_headers);
     $mail =& Mail::factory('mail', "-f " . $GLOBALS["config"]["COMPANY_CONTACT_EMAIL"]);
     $status = $mail->send($email_to, $mail_headers, $mail_body);
     if (PEAR::isError($status)) {
         log_write("error", "inc_credits", "An error occured whilst attempting to send the email: " . $status->getMessage() . "");
     } else {
         log_write("debug", "inc_credits", "Successfully sent email invoice");
         /*
         	Start SQL Transaction to post email to journal
         */
         $sql_obj = new sql_query();
         $sql_obj->trans_begin();
         /*
         	Mark the invoice as having been sent
         */
         $sql_obj = new sql_query();
         $sql_obj->string = "UPDATE account_" . $this->type . " SET date_sent='" . date("Y-m-d") . "', sentmethod='email' WHERE id='" . $this->id . "'";
         $sql_obj->execute();
         /*
         	Add the email information to the journal, including attaching a copy
         	of the generated PDF
         */
         log_write("debug", "inc_credits", "Uploading PDF and email details to journal...");
         // create journal entry
         $journal = new journal_process();
         $journal->prepare_set_journalname("account_" . $this->type);
         $journal->prepare_set_customid($this->id);
         $journal->prepare_set_type("file");
         $journal->prepare_set_title("EMAIL: {$email_subject}");
         $data["content"] = NULL;
         $data["content"] .= "To:\t" . $email_to . "\n";
         $data["content"] .= "Cc:\t" . $email_cc . "\n";
         $data["content"] .= "Bcc:\t" . $email_bcc . "\n";
         $data["content"] .= "From:\t" . $email_sender . "\n";
         $data["content"] .= "\n";
         $data["content"] .= $email_message;
         $data["content"] .= "\n";
         $journal->prepare_set_content($data["content"]);
         $journal->action_update();
         // create journal entry
         $journal->action_lock();
         // lock it to prevent any changes to historical record of delivered email
         // upload PDF file as an attachement
         $file_obj = new file_storage();
         $file_obj->data["type"] = "journal";
         $file_obj->data["customid"] = $journal->structure["id"];
         if (!$file_obj->action_update_file($tmp_filename)) {
             log_write("error", "inc_credits", "Unable to upload emailed PDF to journal entry");
         }
         /*
         	Commit
         */
         if (error_check()) {
             $sql_obj->trans_rollback();
         } else {
             $sql_obj->trans_commit();
         }
     }
     // end if successful send
     // cleanup - remove the temporary files
     log_debug("inc_credits", "Performing cleanup - removing temporary file {$tmp_filename}");
     unlink($tmp_filename);
     // return
     if (error_check()) {
         return 0;
     } else {
         return 1;
     }
 }
 function email_invoice($email_sender, $email_to, $email_cc, $email_bcc, $email_subject, $email_message)
 {
     log_debug("invoice", "Executing email_invoice([options])");
     // external dependency of Mail_Mime
     if (!@(include_once 'Mail.php')) {
         log_write("error", "invoice", "Unable to find Mail module required for sending email");
         return 0;
     }
     if (!@(include_once 'Mail/mime.php')) {
         log_write("error", "invoice", "Unable to find Mail::Mime module required for sending email");
         return 0;
     }
     // track attachment files to tidy up
     $file_attachments = array();
     /*
     	Prepare Email Mime Data & Headers
     */
     // fetch sender address
     //
     // users have the choice of sending as the company or as their own staff email address & name.
     //
     if ($email_sender == "user") {
         // send as the user
         $email_sender = "\"" . user_information("realname") . "\" <" . user_information("contact_email") . ">";
     } else {
         // send as the system
         $email_sender = "\"" . sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_NAME'") . "\" <" . sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_CONTACT_EMAIL'") . ">";
     }
     // prepare headers
     $mail_headers = array('From' => $email_sender, 'Subject' => $email_subject, 'Cc' => $email_cc, 'Bcc' => $email_bcc);
     $mail_mime = new Mail_mime("\n");
     $mail_mime->setTXTBody($email_message);
     /*
     	Generate a PDF of the invoice and save to tmp file
     */
     log_debug("invoice", "Generating invoice PDF for emailing");
     // generate PDF
     $this->generate_pdf();
     if (error_check()) {
         return 0;
     }
     // save to a temporary file
     if ($this->type == "ar") {
         $tmp_file_invoice = file_generate_name($GLOBALS["config"]["PATH_TMPDIR"] . "/invoice_" . $this->data["code_invoice"] . "", "pdf");
     } else {
         $tmp_file_invoice = file_generate_name($GLOBALS["config"]["PATH_TMPDIR"] . "/quote_" . $this->data["code_quote"] . "", "pdf");
         //$email_template	= sql_get_singlevalue("SELECT value FROM config WHERE name IN('TEMPLATE_QUOTE_EMAIL') LIMIT 1");
     }
     if (!($fhandle = fopen($tmp_file_invoice, "w"))) {
         log_write("error", "invoice", "A fatal error occured whilst writing invoice PDF to file {$tmp_file_invoice}, unable to send email");
         return 0;
     }
     fwrite($fhandle, $this->obj_pdf->output);
     fclose($fhandle);
     // attach
     $mail_mime->addAttachment($tmp_file_invoice, 'application/pdf');
     $file_attachments[] = $tmp_file_invoice;
     /*
     	Fetch Extra Attachments
     
     	Certain billing processes may add file attachments to the journal that should be sent along with the invoice
     	when an email is generated.
     
     	Here we grab those file attachments and send each one.
     */
     $obj_sql_journal = new sql_query();
     $obj_sql_journal->string = "SELECT id FROM journal WHERE journalname='account_ar' AND customid='" . $this->id . "' AND title LIKE 'SERVICE:%'";
     $obj_sql_journal->execute();
     if ($obj_sql_journal->num_rows()) {
         $obj_sql_journal->fetch_array();
         foreach ($obj_sql_journal->data as $data_journal) {
             // there are journaled attachments to send
             //
             // we don't care about any of the journal data, we just need to pull the file attachment from
             // storage, write to disk and then attach to the email
             //
             // fetch file object
             $file_obj = new file_storage();
             $file_obj->data["type"] = "journal";
             $file_obj->data["customid"] = $data_journal["id"];
             if (!$file_obj->load_data_bytype()) {
                 log_write("error", "inc_invoices", "Unable to load file from journal to attach to invoice email - possible file storage issue?");
                 return 0;
             }
             $file_extension = format_file_extension($file_obj->data["file_name"]);
             $file_name = format_file_noextension($file_obj->data["file_name"]);
             $file_ctype = format_file_contenttype($file_extension);
             // we have to write the file to disk before attaching it
             $tmp_file_attach = file_generate_name($GLOBALS["config"]["PATH_TMPDIR"] . "/" . $file_name, $file_extension);
             if (!$file_obj->filedata_write($tmp_file_attach)) {
                 log_write("error", "inc_invoices", "Unable to write file attachments from journal to tmp space");
                 return 0;
             }
             // add to the invoice
             $mail_mime->addAttachment($tmp_file_attach, $file_ctype);
             $file_attachments[] = $tmp_file_attach;
             // cleanup - tmp file will be removed ;ater
             unset($file_obj);
         }
         // end of for each journal item
     }
     // end if sendable journal items
     unset($obj_sql_journal);
     /*
     	Email the invoice
     */
     log_write("debug", "invoice", "Sending generated email....");
     $mail_body = $mail_mime->get();
     $mail_headers = $mail_mime->headers($mail_headers);
     $mail =& Mail::factory('mail', "-f " . $GLOBALS["config"]["COMPANY_CONTACT_EMAIL"]);
     $status = $mail->send($email_to, $mail_headers, $mail_body);
     if (PEAR::isError($status)) {
         log_write("error", "inc_invoice", "An error occured whilst attempting to send the email: " . $status->getMessage() . "");
     } else {
         log_write("debug", "inc_invoice", "Successfully sent email invoice");
         /*
         	Start SQL Transaction to post email to journal
         */
         $sql_obj = new sql_query();
         $sql_obj->trans_begin();
         /*
         	Mark the invoice as having been sent
         */
         $sql_obj = new sql_query();
         $sql_obj->string = "UPDATE account_" . $this->type . " SET date_sent='" . date("Y-m-d") . "', sentmethod='email' WHERE id='" . $this->id . "'";
         $sql_obj->execute();
         /*
         	Add the email information to the journal, including attaching a copy
         	of the generated PDF
         */
         log_write("debug", "inc_invoice", "Uploading PDF and email details to journal...");
         // create journal entry
         $journal = new journal_process();
         $journal->prepare_set_journalname("account_" . $this->type);
         $journal->prepare_set_customid($this->id);
         $journal->prepare_set_type("file");
         $journal->prepare_set_title("EMAIL: {$email_subject}");
         $data["content"] = NULL;
         $data["content"] .= "To:\t" . $email_to . "\n";
         $data["content"] .= "Cc:\t" . $email_cc . "\n";
         $data["content"] .= "Bcc:\t" . $email_bcc . "\n";
         $data["content"] .= "From:\t" . $email_sender . "\n";
         $data["content"] .= "\n";
         $data["content"] .= $email_message;
         $data["content"] .= "\n";
         $journal->prepare_set_content($data["content"]);
         $journal->action_update();
         // create journal entry
         $journal->action_lock();
         // lock it to prevent any changes to historical record of delivered email
         // upload PDF file as an attachement
         $file_obj = new file_storage();
         $file_obj->data["type"] = "journal";
         $file_obj->data["customid"] = $journal->structure["id"];
         if (!$file_obj->action_update_file($tmp_file_invoice)) {
             log_write("error", "inc_invoice", "Unable to upload emailed PDF to journal entry");
         }
         /*
         	Commit
         */
         if (error_check()) {
             $sql_obj->trans_rollback();
         } else {
             $sql_obj->trans_commit();
         }
     }
     // end if successful send
     // cleanup - remove the temporary files
     log_debug("inc_invoice", "Performing cleanup, removing temporary files used for emails");
     foreach ($file_attachments as $filename) {
         log_debug("inc_invoice", "Removing tmp file {$filename}");
         unlink($filename);
     }
     // return
     if (error_check()) {
         return 0;
     } else {
         return 1;
     }
 }
 function execute()
 {
     // establish a new table object
     $this->obj_table = new table();
     $this->obj_table->language = $_SESSION["user"]["lang"];
     $this->obj_table->tablename = "account-statements";
     // define all the columns and structure
     $this->obj_table->add_column("standard", "code_invoice", "account_ar.code_invoice");
     $this->obj_table->add_column("standard", "code_ordernumber", "account_ar.code_ordernumber");
     $this->obj_table->add_column("standard", "code_ponumber", "account_ar.code_ponumber");
     $this->obj_table->add_column("standard", "name_customer", "CONCAT_WS(' -- ', customers.code_customer, customers.name_customer)");
     $this->obj_table->add_column("standard", "name_staff", "CONCAT_WS(' -- ', staff.staff_code, staff.name_staff)");
     $this->obj_table->add_column("date", "date_trans", "account_ar.date_trans");
     $this->obj_table->add_column("date", "date_due", "account_ar.date_due");
     $this->obj_table->add_column("price", "amount_tax", "account_ar.amount_tax");
     $this->obj_table->add_column("price", "amount", "account_ar.amount");
     $this->obj_table->add_column("price", "amount_total", "account_ar.amount_total");
     $this->obj_table->add_column("price", "amount_paid", "account_ar.amount_paid");
     $this->obj_table->add_column("date", "date_sent", "account_ar.date_sent");
     $this->obj_table->add_column("bool_tick", "sent", "account_ar.sentmethod");
     $this->obj_table->add_column("standard", "days_overdue", "DATEDIFF(CURDATE(), account_ar.date_due)");
     $this->obj_table->add_column("standard", "send_reminder", "NONE");
     // defaults
     $this->obj_table->columns = array("code_invoice", "name_customer", "amount_total", "date_due", "date_sent", "days_overdue", "send_reminder");
     $this->obj_table->columns_order = array("date_due");
     $this->obj_table->columns_order_options = array("code_invoice", "name_customer", "amount_total", "date_due", "date_sent", "days_overdue", "send_reminder");
     // define SQL structure
     $this->obj_table->sql_obj->prepare_sql_settable("account_ar");
     $this->obj_table->sql_obj->prepare_sql_addfield("id", "account_ar.id");
     $this->obj_table->sql_obj->prepare_sql_addfield("since_sent", "DATEDIFF(CURDATE(), account_ar.date_sent)");
     $this->obj_table->sql_obj->prepare_sql_addjoin("LEFT JOIN customers ON customers.id = account_ar.customerid");
     $this->obj_table->sql_obj->prepare_sql_addjoin("LEFT JOIN staff ON staff.id = account_ar.employeeid");
     $this->obj_table->sql_obj->prepare_sql_addwhere("account_ar.amount_total > account_ar.amount_paid");
     // acceptable filter options
     $structure = NULL;
     $structure["fieldname"] = "days_overdue";
     $structure["type"] = "input";
     $structure["sql"] = "DATEDIFF(CURDATE(), account_ar.date_due) >= 'value'";
     $structure["options"]["width"] = 30;
     $structure["defaultvalue"] = $GLOBALS["config"]["ACCOUNTS_TERMS_DAYS"];
     $this->obj_table->add_filter($structure);
     $structure = NULL;
     $structure["fieldname"] = "date_start";
     $structure["type"] = "date";
     $structure["sql"] = "date_trans >= 'value'";
     $this->obj_table->add_filter($structure);
     $structure = NULL;
     $structure["fieldname"] = "date_end";
     $structure["type"] = "date";
     $structure["sql"] = "date_trans <= 'value'";
     $this->obj_table->add_filter($structure);
     $structure = form_helper_prepare_dropdownfromdb("employeeid", "SELECT id, staff_code as label, name_staff as label1 FROM staff ORDER BY name_staff");
     $structure["sql"] = "account_ar.employeeid='value'";
     $structure["options"]["search_filter"] = "enabled";
     $this->obj_table->add_filter($structure);
     $structure = form_helper_prepare_dropdownfromdb("customerid", "SELECT id, code_customer as label, name_customer as label1 FROM customers ORDER BY name_customer");
     $structure["sql"] = "account_ar.customerid='value'";
     $structure["options"]["search_filter"] = "enabled";
     $this->obj_table->add_filter($structure);
     // load options
     $this->obj_table->load_options_form();
     // minimum of 1 days overdue
     if ($this->obj_table->filter["filter_days_overdue"]["defaultvalue"] < 1) {
         $this->obj_table->filter["filter_days_overdue"]["defaultvalue"] = 1;
     }
     // fetch all the chart information
     $this->obj_table->generate_sql();
     $this->obj_table->load_data_sql();
     //establish new form object
     $this->obj_form = new form_input();
     $this->obj_form->formname = "account-statements";
     $this->obj_form->language = $_SESSION["user"]["lang"];
     $this->obj_form->action = "accounts/ar/account-statements-process.php";
     $this->obj_form->method = "post";
     //create form fields
     for ($i = 0; $i < $this->obj_table->data_num_rows; $i++) {
         $structure = NULL;
         $structure["fieldname"] = "send_reminder_{$i}";
         $structure["type"] = "checkbox";
         $structure["options"]["nolabel"] = "true";
         $this->obj_form->add_input($structure);
         $structure = NULL;
         $structure["fieldname"] = "invoice_id_{$i}";
         $structure["type"] = "hidden";
         $structure["defaultvalue"] = $this->obj_table->data[$i]["id"];
         $this->obj_form->add_input($structure);
         $structure = NULL;
         $structure["fieldname"] = "days_overdue_{$i}";
         $structure["type"] = "hidden";
         $structure["defaultvalue"] = $this->obj_table->data[$i]["days_overdue"];
         $this->obj_form->add_input($structure);
     }
     //form fields for email options
     $structure = NULL;
     $structure["fieldname"] = "sender";
     $structure["type"] = "radio";
     $structure["defaultvalue"] = "system";
     $structure["values"] = array("system", "user");
     $structure["translations"]["system"] = sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_NAME'") . " &lt;" . sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_CONTACT_EMAIL'") . "&gt;";
     $structure["translations"]["user"] = user_information("realname") . " &lt;" . user_information("contact_email") . "&gt;";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "subject";
     $structure["type"] = "input";
     $structure["defaultvalue"] = "Overdue Notice: Invoice (code_invoice)";
     $structure["options"]["width"] = "600";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "email_message";
     $structure["type"] = "textarea";
     $structure["defaultvalue"] = sql_get_singlevalue("SELECT value FROM config WHERE name IN('TEMPLATE_INVOICE_REMINDER_EMAIL') LIMIT 1");
     $structure["options"]["width"] = "600";
     $structure["options"]["height"] = "100";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "num_records";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->obj_table->data_num_rows;
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "submit";
     $structure["type"] = "submit";
     $structure["defaultvalue"] = "Send Reminders";
     $this->obj_form->add_input($structure);
     //load any error data
     $this->obj_form->load_data();
 }