Roundcube Community Forum

 

Global Addressbook with hosted webspace....how?

Started by WeVo, December 19, 2006, 02:45:36 PM

Previous topic - Next topic

WeVo

Hello,

we use with our club roundcube. I have installed it on a normal hosted webspace. Now we want to have a global addressbook. How is it possible to use that, because i have no Ldap server.

Is there any way to have an addressbook without a ldapserver where the admin or user can create new contacts and every user can see this contacts.
Thanks a lot for your help!

greetings to the world

Markus

owenhau

May be...correct me if wrong...XD
Do a small hack in the file list.inc in program/steps/addressbook/

I've not did this test so...on your own risk...backup anything before your work

modify your rc db table:
ALTER TABLE `roundcubemail`.`contacts` ADD COLUMN `shared` TINYINT(1) SIGNED NOT NULL DEFAULT 0;

Modify list.inc
1 ;D
Quote// count contacts for this user
$sql_result = $DB->query("SELECT COUNT(contact_id) AS rows
             FROM ".get_table_name('contacts')."
             WHERE del<>1
             AND  user_id=?",
             $_SESSION['user_id']);
to
Quote// count contacts for this user
$sql_result = $DB->query("SELECT COUNT(contact_id) AS rows
             FROM ".get_table_name('contacts')."
             WHERE del<>1
             AND  user_id=?
             OR shared = 1",
             $_SESSION['user_id']);
2 :D
Quote// get contacts from DB
$sql_result = $DB->limitquery("SELECT * FROM ".get_table_name('contacts')."
                WHERE del<>1
                AND  user_id=?
                ORDER BY name",
                $start_row,
                $CONFIG['pagesize'],
                $_SESSION['user_id']);
to
Quote// get contacts from DB
$sql_result = $DB->limitquery("SELECT * FROM ".get_table_name('contacts')."
                WHERE del<>1
                AND  user_id=?
                OR shared = 1
                ORDER BY name",
                $start_row,
                $CONFIG['pagesize'],
                $_SESSION['user_id']);

This will show the contact which marked shared=1 in the table.
If you trust your user, this may allow all the user to modify/delete the shared contact.

The step you need to do sharing of contacts is a little bit...um....um.....
directly edit the table and change the column "shared" of that row to "1"

Remember, I don't know it works or not...XD

WeVo

OK thanks.
Have i any possibility that only i as admin can create, delete and edit the global contacts?

owenhau

I'm not sure the list.inc is for addressbook page or the dynamic menu of receiptxxx....(Oh...my poor english...) in the composer.

If you tried that script can show the shared contact at the composer but not in the addressbook page, then for your administration:

Create a new user, add/manage the share contact...
Run a sql script every time you updated the contact
UPDATE `contacts` set shared = 1 where user_id =

if you can't show the shared contact at the composer then....(Turn my head around and shout: Any one know the dynamic menu's function was load from which files ?)

but if you can see the shared contact in addressbook and not in the composer, may be i've got something wrong in above code. try to replace the original list.inc file and change the show.inc file

Quote$DB->query("SELECT * FROM ".get_table_name('contacts')."
       WHERE contact_id=?
       AND  user_id=?
       AND  del<>1",
       $cid,
       $_SESSION['user_id']);
to
Quote$DB->query("SELECT * FROM ".get_table_name('contacts')."
       WHERE (contact_id=?
       AND  user_id=?
       AND  del<>1")
       OR shared=1,
       $cid,
       $_SESSION['user_id']);

right, it seem i've missing the () in the above post...XD

seansan


The direction looks good.... I was just thinking that maybe you can also create a linked table and update the get_table_name to UNION (or MySQL equivalent) with the shared table. I dont know how one would then disable the editing.

robin.one

It took me a few hours, but I combined your parts of your idea with the parts from this post - http://roundcubeforum.net/forum/index.php?topic=584.0

This makes every contact added shared amongst all users. It's what I needed anyway.

Basically I added the column as you suggested, but then used it in a different way.

Instead of adding the OR shared=1 on a separate line I changed all entries of user_id=? in the following files to ( user_id=? OR shared=0 ) - including the parenthesis.

/program/steps/mail/compose.inc
/program/steps/addressbook/delete.inc
/program/steps/addressbook/edit.inc
/program/steps/addressbook/func.inc
/program/steps/addressbook/list.inc
/program/steps/addressbook/show.inc

Now every contact added will default the shared field to 0 since there's no option put in your own value, and all users will see every entry. You can still manually change the shared field to 1 for the ones that you don't want to share. Hopefully an input when adding or editing contacts for shared can be developed sometime soon, and an admin panel.

Cheers

kmn

Hello,

This folder and file structure seems to have changed in ver.1rc1. Could somebody please point to the correct locations?

Thanks

kmn

rcayadi

This is my quick and dirty method (It only a very quick solution and take 1 hours to modify so please im sorry if this code very dirty)

1. ALTER TABLE `roundcubemail`.`contacts` ADD COLUMN `shared` char(2) NOT NULL DEFAULT 'on';

2. Modify program/include/rcube_contacts.inc become like this
On function list_records
.....
     WHERE del<>1
     AND  ( user_id=? OR shared='on' )&quot;.
    ($this->filter ? &quot; AND (&quot;.$this->filter.&quot;)&quot; : &quot;&quot;) .
    &quot; ORDER BY name&quot;,
....
On function count()
...
 WHERE del<>1
    AND  ( user_id=? OR shared='on' )".
    ($this->filter ? " AND (".$this->filter.")" : ""),
...
On function get_record()
...
   WHERE contact_id=?
    AND  ( user_id=? OR shared='on' )
    AND  del<>1",
...

3. Modify program/steps/addressbook/edit.inc So there is additional Share Address Book Checkbox options
(around line 64)
$a_show_cols = array('name', 'firstname', 'surname', 'email');Become
$a_show_cols = array('name', 'firstname', 'surname', 'email','shared');
(around line 69)
$out .= sprintf("%s\n",
          $attrib['id'],
          Q(rcube_label($col)),
          $value);
Become
if ($col == 'shared') {
if ($record[$col] == 'on') $cek = "checked"; else $cek = " ";
$out .= "";
  } else {
  $out .= sprintf("%s\n",
          $attrib['id'],
          Q(rcube_label($col)),
          $value);
  }


4. Modify function insert on program/include/rcube_contacts.inc  
var $table_cols = array('name', 'email', 'firstname', 'surname');Become ....
var $table_cols = array('name', 'email', 'firstname', 'surname','shared');  
$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);
Become ........
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, shared, del, ".join(', ', $a_insert_cols).")
     VALUES (?, ".$this->db->now().", '1', 0, ".join(', ', $a_insert_values).")",
    $this->user_id);
}  

Regards
RUdy Cayadi