예제 #1
0
 function add($VAR)
 {
     $type = "add";
     $this->method["{$type}"] = explode(",", $this->method["{$type}"]);
     $db = new CORE_database();
     $group_id = $db->add($VAR, $this, $type);
     # add the new group to the account_group table:
     $db =& DB();
     $record_id = $db->GenID(AGILE_DB_PREFIX . 'account_group_id');
     $sql = "INSERT INTO " . AGILE_DB_PREFIX . "account_group SET\n\t\t\t\tid\t\t\t= " . $db->qstr($record_id) . ",\n\t\t\t\tsite_id \t= " . $db->qstr(DEFAULT_SITE) . ", \n\t\t\t\tdate_orig\t= " . $db->qstr(time()) . ",\n\t\t\t\tdate_expire = " . $db->qstr('0') . ",\n\t\t\t\tgroup_id\t= " . $db->qstr($group_id) . ",\n\t\t\t\taccount_id\t= " . $db->qstr(SESS_ACCOUNT) . ",\n\t\t\t\tactive\t\t= " . $db->qstr(1);
     $result = $db->Execute($sql);
     if ($result === false) {
         global $C_debug;
         $C_debug->error('list.inc.php', 'select_groups', $db->ErrorMsg());
         return;
     }
     # update the current user's authentication so the newly added group appears
     # as available to them
     global $C_auth;
     $C_auth->auth_update();
     return;
 }
예제 #2
0
    function view($VAR)
    {
        global $smarty;
        $this->construct();
        $type = "view";
        $this->method["{$type}"] = split(",", $this->method["{$type}"]);
        $db = new CORE_database();
        $db->view($VAR, $this, $type);
        ### Define the group mapping....
        $id = @$VAR['id'];
        ### Get the variables for this map plugin:
        $db =& DB();
        $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'db_mapping WHERE
			  id      = ' . $db->qstr(@$VAR["id"]) . ' AND
			  site_id = ' . $db->qstr(DEFAULT_SITE);
        $result = $db->Execute($sql);
        ### error reporting:
        if ($result === false) {
            global $C_debug;
            $C_debug->error('db_mapping.inc.php', 'view', $db->ErrorMsg());
            return;
        }
        $file = $result->fields['map_file'];
        $group_map = $result->fields['group_map'];
        if ($group_map != '') {
            $group_map = unserialize($group_map);
        } else {
            $group_map = array();
        }
        if ($file != '') {
            include_once PATH_PLUGINS . 'db_mapping/' . $file . '.php';
            eval('$_MAP = new map_' . strtoupper($file) . ';');
            ### If this map type is 'db' groups based:
            if ($_MAP->map['group_type'] == 'db' || $_MAP->map['group_type'] == 'db-status') {
                ### Connect to the DB & get the groups:
                $dbm = new db_mapping();
                $db = $dbm->DB_connect($id, 'false');
                eval('@$db_prefix = DB2_PREFIX' . strtoupper($file) . ';');
                $sql = "SELECT * FROM " . $db_prefix . "" . $_MAP->map['group_map']['table'] . "\n\t\t\t\t\t\t\t ORDER BY      " . $_MAP->map['group_map']['name'];
                $db2 = $db->Execute($sql);
                if ($db2 === false) {
                    global $C_debug;
                    $C_debug->error('db_mapping.inc.php', 'view', $db->ErrorMsg());
                    $smarty->assign('db_mapping_result', $db->ErrorMsg());
                    return;
                }
                ### get the remote groups...
                if ($db2->RecordCount() > 0) {
                    $i = 0;
                    while (!$db2->EOF) {
                        $smart[$i]['id'] = $db2->fields[$_MAP->map['group_map']['id']];
                        $smart[$i]['name'] = $db2->fields[$_MAP->map['group_map']['name']];
                        $db2->MoveNext();
                        $i++;
                    }
                    ### Get the local groups:
                    $db =& DB();
                    $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'group WHERE
							site_id = ' . $db->qstr(DEFAULT_SITE) . '
							ORDER BY name';
                    $groups = $db->Execute($sql);
                    if ($groups === false) {
                        global $C_debug;
                        $C_debug->error('db_mapping.inc.php', 'view', $db->ErrorMsg());
                        return;
                    }
                    if ($groups->RecordCount() > 0) {
                        $i = 0;
                        while (!$groups->EOF) {
                            $id = $groups->fields['id'];
                            $smartgr[$i]['id'] = $groups->fields['id'];
                            $smartgr[$i]['name'] = $groups->fields['name'];
                            for ($ii = 0; $ii < count($smart); $ii++) {
                                $rid = $smart[$ii]['id'];
                                $name = $smart[$ii]['name'];
                                $checked = false;
                                if (isset($group_map[$id][$rid]) && $group_map[$id][$rid] != false) {
                                    $checked = true;
                                }
                                $smartgr[$i]['remote'][$ii]['id'] = $rid;
                                $smartgr[$i]['remote'][$ii]['name'] = $name;
                                $smartgr[$i]['remote'][$ii]['check'] = $checked;
                            }
                            $groups->MoveNext();
                            $i++;
                        }
                        ### Define smarty vars
                        $smarty->assign('db_mapping_result', false);
                        $smarty->assign('db_mapping_template', 'db_mapping:group_map_' . $_MAP->map['group_type']);
                        $smarty->assign('db_mapping_groups', $smartgr);
                    } else {
                        global $C_translate;
                        $message = $C_translate->translate('no_local_groups', 'db_mapping', '');
                        $smarty->assign('db_mapping_result', $message);
                    }
                } else {
                    global $C_translate;
                    $message = $C_translate->translate('no_remote_groups', 'db_mapping', '');
                    $smarty->assign('db_mapping_result', $message);
                }
            } elseif ($_MAP->map['group_type'] == 'status') {
                ### This is at 'status' based database map
                ### Get the local groups:
                $db =& DB();
                $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'group WHERE
						site_id = ' . $db->qstr(DEFAULT_SITE) . '
						ORDER BY name';
                $groups = $db->Execute($sql);
                ### error reporting:
                if ($groups === false) {
                    global $C_debug;
                    $C_debug->error('db_mapping.inc.php', 'view', $db->ErrorMsg());
                    return;
                }
                if ($groups->RecordCount() > 0) {
                    $i = 0;
                    while (!$groups->EOF) {
                        $id = $groups->fields['id'];
                        $smart[$i]['id'] = $groups->fields['id'];
                        $smart[$i]['name'] = $groups->fields['name'];
                        @($smart[$i]['value'] = $group_map[$id]);
                        $groups->MoveNext();
                        $i++;
                    }
                }
                ### Assign the smarty vars:
                $smarty->assign('db_mapping_result', false);
                $smarty->assign('db_mapping_template', 'db_mapping:group_map_status');
                $smarty->assign('db_mapping_groups', $smart);
            } else {
                ### No group mapping for this database map
                global $C_translate;
                $message = $C_translate->translate('no_group_mapping', 'db_mapping', '');
                $smarty->assign('db_mapping_result', $message);
            }
        } else {
            global $C_translate;
            $message = $C_translate->translate('file_error', 'db_mapping', '');
            $smarty->assign('db_mapping_result', $message);
        }
    }