Help, php guru's! :)

K

Krunoslav

Guest
First of all, I would like to say that Dadabik is excellent. Fantastic job. I'm not very familiar with php coding, but installation and configuration was very easy, and I also made some small "tweaks" to make it work how I want it to. But, since I'm not very good at php coding, I don't know how to make this "final tweak" which would make this program fabolous for my needs. Here is the problem, or, better said, my wish:

I have adressbok of my costumers which contains Adress, phone no., e-mail etc...

But often I have to send mail (not e-mail) to certain costumers which I find in my database. Unfortunately, I have to copy/paste those adresses one by one to Text editor, and then print them out on envelopes.

So, what I want: to find costumers in my database, and then to have button like "Print on envelope" near export to CSV button , which would print Name, Adress and Postal code on envelope, starting 21cm from left edge and 9cm from top edge.

I know I'm asking a lot, but if you would just give me hint how to make something like this, I would really appreciate it...
 
D

Debbie S

Guest
Krunoslav

Here you go ... I've included the code, line numbers and surrounding text for you to work with in each of the files. Text noted in italics is what you will INSERT.

index.php:
Near line 517:
txt_out("<h3>".$normal_messages_ar["details_of_record"]."</h3>");

txt_out("<a class=\"onlyscreen\" target=\"_".$edit_target_window."\" href=\"".$dadabik_main_file."?table_name=".urlencode($table_name)."&function=printenv&where_field=".urlencode($where_field)."&where_value=".urlencode($where_value)."\">Print to Envelope</a><p>");

// execute the select query
$res_details = execute_db("$sql", $conn);


include/business_logic.php:
Near line 2567:
} // end function build_details_table

function build_printenv_table($fields_labels_ar, $res_details)
// goal: build an html table with details of a record
// input: $fields_labels_ar $res_details (the result of the query)
// ouptut: $details_table, the html table
{
global $conn, $quote, $alias_prefix;

// build the table
$printenv_table = "";

$printenv_table .= "<table><tr><td height=\"262\"> </td></tr>";

while ($details_row = fetch_row_db($res_details)){ // should be just one

$count_temp = count($fields_labels_ar);
for ($i=0; $i<$count_temp; $i++){
if ($fields_labels_ar[$i]["present_details_form_field"] == "1"){
$field_name_temp = $fields_labels_ar[$i]["name_field"];

$field_values_ar = array(); // reset the array containing values to display, otherwise for each loop if I don't call build_linked_field_values_ar I have the previous values

$primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
if ($primary_key_field_field != ""){
$primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
$primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
$primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
$linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
$linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);
$alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"];

for ($j=0;$j<count($linked_fields_ar);$j++) {
$field_values_ar[$j] .= $details_row[$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];

} // end for

/*
$linked_field_values_ar = build_linked_field_values_ar($details_row[$field_name_temp], $primary_key_field_field, $primary_key_table_field, $primary_key_db_field, $linked_fields_ar);
*/
/*
if (substr($foreign_key_temp, 0, 4) == "SQL:"){
$sql = substr($foreign_key_temp, 4, strlen($foreign_key_temp)-4);
} // end if
else{
*/
//$field_values_ar = $linked_field_values_ar;
}
else{
$field_values_ar[0] = $details_row[$field_name_temp];
}

$count_temp_2 = count($field_values_ar);
$printenv_table .= "<tr><td width=\"772\"> </td><td class=\"td_value_details\">";
for ($j=0; $j<$count_temp_2; $j++) {
$field_to_display = get_field_correct_displaying($field_values_ar[$j], $fields_labels_ar[$i]["type_field"], $fields_labels_ar[$i]["content_field"], $fields_labels_ar[$i]["separator_field"], "printenv_table"); // get the correct display mode for the field

$printenv_table .= $field_to_display." "; // at the field value to the table
}
$printenv_table = substr($printenv_table, 0, -6); // delete the last  
$printenv_table .= "</td></tr>";

} // end if
} // end for
} // end while

$printenv_table .= "</table>";

return $printenv_table;
} // end function build_printenv_table

function build_navigation_tool


include/footer.php **:
Near line 107:
<div align="left" class="onlyscreen"><font size="1">Powered by: DaDaBIK</font></div>

** NOTE: Anything else you see in the header/footer files that you do not want to print can have the class="onlyscreen" added to it. The other option may be to create a new page that does not call the header or footer for DaDaBIK - just remember to include all necessary files in order for it to work.

The height and width measurements (shown in bold in the business_logic addition) are based on the default IE margins of 2cm calculated at 37.5 pixels per CM. You may need to play with these measurements or add a spacer graphic to ensure the measurements display correctly on the resulting page.

IMPORTANT!
It is IMPOSSIBLE to remove the header/footer lines that IE automatically prints on pages from a browser using CSS or scripting (so far). So, this is what I do when I do not want those items to print:

Create a text file to hold the settings you currently have in IE for your page setup. From IE, select File > Page Setup... from the menu and copy the values from the header and footer box into your text file. Save your text file and delete the header/footer values from the IE page setup. Now when you print, there will be nothing but the content of the page (in your case, the address) printed.

Hope this helps!

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
K

Krunoslav

Guest
What exactly should happen when I click on "Print on envelope"? I inserted the code, and got "Print on envelope", but when I click on it, nothing happens. I get only empty page with header and footer, but nothing is displayed or printed...
 
K

Krunoslav

Guest
Let me try to make it easier for you by explaining exact table structure: For every record, I have name, adress, city, zip, mail, tel, fax, type . These are also exact names of the fields in the table, and table name is contacts. So, when I get details from one record, I also have informations I don't need to be printed. I have to print envelope in this format:

name
adress
zip city

That's all. Maybe this will help you...
 
D

Debbie S

Guest
Krunoslav

Sorry ... I forgot one block of code for the index.php page:

Just above line 566, insert the code in italics:

} // end else
break;
case "printenv":
if ($enable_authentication === 0 || $enable_browse_authorization === 0 || current_user_is_owner($where_field, $where_value, $table_name, $fields_labels_ar)){
// build the details select query
//$sql = "select * from ".$quote.$table_name.$quote." where ".$quote.$where_field.$quote." = '".$where_value."'";

$sql = build_select_part($fields_labels_ar, $table_name);

$sql .= " where ".$quote.$where_field.$quote." = '".$where_value."' LIMIT 1";

display_sql($sql);

// txt_out("<h3>".$normal_messages_ar["details_of_record"]."</h3>");

// execute the select query
$res_details = execute_db("$sql", $conn);

// build the HTML details table
$printenv_table = build_printenv_table($fields_labels_ar, $res_details);

// display the HTML details table
echo $printenv_table;
} // end if
else {
txt_out("<p>".$error_messages_ar["no_authorization_view"]."</p>");
} // end else
break;

case "edit":

With this solution, whatever you have set to display in the details view would show on the print envelope view. If you wanted to customize the print envelope view separate from the details view, you would have to write major modifications to the DaDaBIK tables to include a separate view parameter. If this solution does not work for you, a separate page/script may be required in order to print only the items you want available.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
Top