Hi there,
I would like to start off by thanking all the contributors here for the codes to modify the existing address book into one that can do global address book which contain additional fields and additional email addresses per contact.
After going through the forum, I found different modification codes to achieve each function. Like one code to enable you to have global address book. Another to have additional fields in individual contact. Another to have additional email addresses per contact.
I had merge all these modification codes into one. I'm attaching the merged codes below. I hope you find it helpful.
Again, I will like to stress that I'm not the original creator of these codes. These codes are done by fellow forum users here whom had done a great job.
After having done this, I hope to have another function. I'm hoping that fellow forum users here can help. I want to have only the administrator manage the global address book. Which means only administrator can create, edit and delete global address book. User are not allow to create, edit and delete global address book.
However, user will still be allowed to create, edit and delete individual (personal) contacts.
Thanks.
# -------------------------------------------------------------------------------------------------------------
#
# Database Additions for contact multiple emails
# Run in PhpMyAdmin on the database that holds the RC Contacts table. Change the table name rc_contacts to your contacts table name:
#
ALTER TABLE `contacts` ADD `global_contact` TINYINT(1) NOT NULL default '0';
ALTER TABLE `contacts` ADD `firm` VARCHAR(128) NOT NULL ;
ALTER TABLE `contacts` ADD `position` VARCHAR(50) NOT NULL ;
ALTER TABLE `contacts` ADD `p_tel` VARCHAR(30) NOT NULL ;
ALTER TABLE `contacts` ADD `p_fax` VARCHAR(30) NOT NULL ;
ALTER TABLE `contacts` ADD `p_mob` VARCHAR(20) NOT NULL ;
ALTER TABLE `contacts` ADD `p_address` TEXT NOT NULL;
ALTER TABLE `contacts` ADD `w_tel` VARCHAR(20) NOT NULL ;
ALTER TABLE `contacts` ADD `w_fax` VARCHAR(20) NOT NULL ;
ALTER TABLE `contacts` ADD `w_mob` VARCHAR(20) NOT NULL ;
ALTER TABLE `contacts` ADD `w_address` TEXT NOT NULL;
ALTER TABLE `contacts` ADD `notice` TEXT NOT NULL;
ALTER TABLE `contacts` ADD `email2` VARCHAR(128) NOT NULL ;
ALTER TABLE `contacts` ADD `email3` VARCHAR(128) NOT NULL ;
ALTER TABLE `contacts` ADD `email4` VARCHAR(128) NOT NULL ;
# -------------------------------------------------------------------------------------------------------------
#
# In file /program/include/rcube_contacts.inc
#
#Locate
var $table_cols = array('name', 'email', 'firstname', 'surname');
#
# and replace with
var $table_cols = array('name', 'firstname', 'surname', 'email', 'email2', 'email3', 'email4', 'global_contact', 'firm', 'position', 'p_tel', 'p_fax', 'p_mob', 'p_address', 'w_tel', 'w_fax', 'w_mob', 'w_address', 'notice');
#
#
#
#locate function...
function list_records($cols=null, $subset=0)
#locate the code....
$sql_result = $this->db->limitquery(
"SELECT * FROM ".$this->db_name."
WHERE del<>1
AND user_id=?" .
($this->filter ? " AND (".$this->filter.")" : "") .
" ORDER BY name",
#
#and replace with
$sql_result = $this->db->limitquery(
"SELECT * FROM ".$this->db_name."
WHERE del<>1
AND (user_id=? OR global_contact = 1)".
($this->filter ? " AND (".$this->filter.")" : "") .
" ORDER BY name",
#
#
#
#locate function...
function count()
#locate the code....
$sql_result = $this->db->query(
"SELECT COUNT(contact_id) AS rows
FROM ".$this->db_name."
WHERE del<>1
AND user_id=?".
($this->filter ? " AND (".$this->filter.")" : ""),
$this->user_id);
#
#and replace with
$sql_result = $this->db->query(
"SELECT COUNT(contact_id) AS rows
FROM ".$this->db_name."
WHERE del<>1
AND (user_id=? OR global_contact = 1)".
($this->filter ? " AND (".$this->filter.")" : ""),
$this->user_id);
#
#
#
#locate function...
function get_record($id, $assoc=false)
#locate the code....
$this->db->query(
"SELECT * FROM ".$this->db_name."
WHERE contact_id=?
AND user_id=?
AND del<>1",
$id,
$this->user_id);
#
#and replace with
$this->db->query(
"SELECT * FROM ".$this->db_name."
WHERE contact_id=?
AND (user_id=? OR global_contact = 1)
AND del<>1",
$id,
$this->user_id);
#
#
#
#locate function...
function update($id, $save_cols)
#locate the code....
if (!empty($write_sql))
{
$this->db->query(
"UPDATE ".$this->db_name."
SET changed=".$this->db->now().", ".join(', ', $write_sql)."
WHERE contact_id=?
AND user_id=?
AND del<>1",
$id,
$this->user_id);
#
#and replace with
if (!empty($write_sql))
{
$this->db->query(
"UPDATE ".$this->db_name."
SET changed=".$this->db->now().", ".join(', ', $write_sql)."
WHERE contact_id=?
AND (user_id=? OR global_contact = 1)
AND del<>1",
$id,
$this->user_id);
#
#
#
#locate function...
function insert($save_data, $check=false)
#locate the code....
$this->db->query(
"INSERT INTO ".$this->db_name."
(user_id, changed, del, ".join(', ', $a_insert_cols).")
VALUES (?, ".$this->db->now().", 0, ".join(', ', $a_insert_values).")",
$this->user_id);
#
#and replace with the following
if ($a_insert_values[4] == "'on'") {
$this->db->query(
"INSERT INTO ".$this->db_name."
(user_id, changed, del, ".join(', ', $a_insert_cols).")
VALUES (?, ".$this->db->now().", 0, ".join(', ', $a_insert_values).")",
$this->user_id);
} else {
$this->db->query(
"INSERT INTO ".$this->db_name."
(user_id, changed, global_contact, del, ".join(', ', $a_insert_cols).")
VALUES (?, ".$this->db->now().", '1', 0, ".join(', ', $a_insert_values).")",
$this->user_id);
}
#
#
#
-------------------------------------------------------------------------------------------------------------
#
# In file /program/include/main.inc
#
#Locate the following function
function rcmail_get_edit_field($col, $value, $attrib, $type='text')
#
#and locate the following code
if ($type=='checkbox')
#
#and replace with the following code
if($col == "notice")
{
$attrib['rows'] = "8";
$attrib['size'] = "40";
$attrib['cols'] = "40";
$input = new textarea($attrib);
}
elseif($col == "p_address" | $col == "w_address")
{
$attrib['rows'] = "4";
$attrib['size'] = "40";
$attrib['cols'] = "40";
$input = new textarea($attrib);
}
else if ($type=='checkbox')
#
#
#
-------------------------------------------------------------------------------------------------------------
#
# In File /program/localization/en_US/label.inc
#
#Locate // address boook
#
#and insert the following labels
$labels['global_contact'] = 'Global Contact';
$labels['firm'] = 'Organization';
$labels['position'] = 'Position';
$labels['p_tel'] = 'Telephone';
$labels['p_fax'] = 'Fax';
$labels['p_mob'] = 'Mobile';
$labels['p_address'] = 'Address';
$labels['w_tel'] = 'Business Telephone';
$labels['w_fax'] = 'Business Fax';
$labels['w_mob'] = 'Business Mobile';
$labels['w_address'] = 'Business Address';
$labels['notice'] = 'Notice';
$labels['email2'] = 'E-Mail 2';
$labels['email3'] = 'E-Mail 3';
$labels['email4'] = 'E-Mail 4';
#
# -------------------------------------------------------------------------------------------------------------
#
#
# In file /program/steps/mail/compose.inc
#
#locate the following if statement
if ($result = $CONTACTS->list_records())
#
#locate the following code
while ($sql_arr = $result->iterate())
if ($sql_arr['email'])
$a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));
#
#and insert the following code after that
if ($sql_arr['email2'])
$a_contacts[] = format_email_recipient($sql_arr['email2'], JQ($sql_arr['name']));
if ($sql_arr['email3'])
$a_contacts[] = format_email_recipient($sql_arr['email3'], JQ($sql_arr['name']));
if ($sql_arr['email4'])
$a_contacts[] = format_email_recipient($sql_arr['email4'], JQ($sql_arr['name']));
#
#
# -------------------------------------------------------------------------------------------------------------
# In file /program/steps/addressbook/edit.inc
#
#locate // return the complete address edit form as table
#
#and the following code
$a_show_cols = array('name', 'firstname', 'surname', 'email');
#
#and replace with the following code
$a_show_cols = array('name', 'firstname', 'surname', 'global_contact', 'email', 'email2', 'email3', 'email4', 'firm', 'position', 'p_tel', 'p_fax', 'p_mob', 'p_address', 'w_tel', 'w_fax', 'w_mob', 'w_address', 'notice');
#
#
# -------------------------------------------------------------------------------------------------------------
#
# In file /program/steps/addressbook/show.inc
#
#Locate // return the complete address record as table
#and the following code
$a_show_cols = array('name', 'firstname', 'surname', 'email');
#
#and replace with the following code
$data ="<td width=\"45%\" valign=\"top\">\n<fieldset width=\"45%\" class=\"title\"><legend><b>Data</b></legend><table>\n\n";
$contact ="<td width=\"45%\" valign=\"top\">\n<fieldset width=\"45%\" class=\"title\"><legend><b>Contact</b></legend><table>\n\n";
$a_show_cols = array('name', 'firstname', 'surname', 'email', 'email2', 'email3', 'email4', 'global_contact', 'firm', 'position', 'p_tel', 'p_fax', 'p_mob', 'p_address', 'w_tel', 'w_fax', 'w_mob', 'w_address', 'notice');
#
#
#Locate the following code
$out .= sprintf("<tr><td class=\"title\">%s</td><td>%s</td></tr>\n",
Q(rcube_label($col)),
$value);
}
$out .= "\n</table>";
#
#and replace with the following code
$title = Q(rcube_label($col));
if($col == "notice"){
$out2 = "<td colspan=\"3\" width=\"100%\" valign=\"top\"><fieldset width=\"100%\" class=\"title\"><legend><b>$title</b></legend><table>\n";
$out2 .= sprintf("<tr><td>%s</td></tr>\n", $value);
$out2 .= "</table></fieldset></td>\n\n";
}
elseif($col == "p_tel" | $col == "p_fax" | $col == "p_mob" | $col == "w_tel" | $col == "w_fax" | $col == "w_mob"){
if(!$value == ""){
$contact .= sprintf("<tr><td>%s</td><td>%s</td></tr>\n",$title, $value);
}
}
elseif($col == "p_address"){
$p_address = "<td width=\"45%\" valign=\"top\"><fieldset width=\"45%\" class=\"title\"><legend><b>$title</b></legend><table>\n";
$p_address .= sprintf("<tr><td>%s</td></tr>\n", $value);
$p_address .= "</table></fieldset></td>\n\n";
}
elseif($col == "w_address"){
$w_address = "<td width=\"45%\" valign=\"top\"><fieldset width=\"45%\" class=\"title\"><legend><b>$title</b></legend><table>\n";
$w_address .= sprintf("<tr><td>%s</td></tr>\n", $value);
$w_address .= "</table></fieldset></td>\n\n";
}
else{
if($col == "global_contact"){
if($value == 1)
$data .= sprintf("<tr><td>%s</td><td>%s</td></tr>\n",$title, 'Yes');
else
$data .= sprintf("<tr><td>%s</td><td>%s</td></tr>\n",$title, 'No');
} else if(!$value == "")
$data .= sprintf("<tr><td>%s</td><td>%s</td></tr>\n",$title, $value);
}
}
$data .= "</table></td>";
$contact .= "</table></td>";
$out .= "$data<td width=\"2%\">$contact\n\n";
$out .= "</tr><tr>";
$out .= "$p_address<td width=\"2%\">$w_address\n\n";
$out .= "</tr><tr>";
$out .= $out2;
$out .= "\n</tr></table>";
#
#
#Locate the following code
if ($col=='email' && !empty($record[$col]))
#
#and replace with the following code
if (($col=='email' || $col=='email2' || $col=='email3' || $col=='email4') && !empty($record[$col]))
#
# -------------------------------------------------------------------------------------------------------------
#
# In file /program/steps/addressbook/save.inc
#
#Locate // setup some vars we need
#and the following code
$a_save_cols = array('name', 'firstname', 'surname', 'email');
#
#and replace with the following code
$a_save_cols = array('name', 'firstname', 'surname', 'email', 'email2', 'email3', 'email4', 'global_contact', 'firm', 'position', 'p_tel', 'p_fax', 'p_mob', 'p_address', 'w_tel', 'w_fax', 'w_mob', 'w_address', 'notice');
#
#
#Locate the folllowing code
if (isset($_POST[$fname]))
#
#and replace with the following code
if($col == 'global_contact'){
if(isset($_POST[$fname])){
$a_record[$col] = 1;
}else{
$a_record[$col] = 0;
}
} else if (isset($_POST[$fname])){
$a_record[$col] = get_input_value($fname, RCUBE_INPUT_POST);
}
#
#
#
#
# -------------------------------------------------------------------------------------------------------------
#Look in the file /skins/default/templates/addressbook.html.
#
#locate the following code that should be around line 31 and line 32
#<style type="text/css">
#addresslist { left:20px; width:440px }
#contacts-box { left:475px }
#abookcountbar { left:20px }
#</style>
#
#
#Modify it to suit your needs. Something like:
#
#addresslist { left:20px; width:250px }
#contacts-box { left:300px }
#
#Note that #addresslist has an initial left position and width. #contacts-box only the initial left position as it uses the rest of the frame width.
#
#
#
#
# -------------------------------------------------------------------------------------------------------------
#
#
# -------------------------------------------------------------------------------------------------------------
#