/**
  *  check if admin have permissions to change user's setting
  *
  *  Possible options parameters:
  *	 - none
  *
  *	@param object $admin		admin - instance of class Auth
  *	@param object $user			admin - instance of class SerwebUser
  *	@param array $opt			associative array of options
  *	@return bool				TRUE on permit, FALSE on forbid, -1 on failure
  */
 function check_admin_perms_to_user(&$admin, &$user, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return -1;
     }
     /* table name */
     $t_name =& $config->data_sql->uri->table_name;
     /* col names */
     $c =& $config->data_sql->uri->cols;
     /* flags */
     $f =& $config->data_sql->uri->flag_values;
     if (false === ($adm_domains = $admin->get_administrated_domains())) {
         return -1;
     }
     $uid = $user->get_uid();
     $q = "select count(*) \n\t\t      from " . $t_name . "\n\t\t\t  where " . $c->uid . " = " . $this->sql_format($uid, "s") . " and \n\t\t\t        " . $this->get_sql_in($c->did, $adm_domains, true) . " and \n\t\t\t\t\t" . $c->flags . " & " . $f['DB_DELETED'] . " = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return -1;
     }
     $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $res->free();
     return $row[0] ? true : false;
 }
 /**
  *	delete all user's records from user_attrs
  */
 function delete_user_attrs($uid)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_name =& $config->data_sql->user_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->user_attrs->cols;
     /* flags */
     $f =& $config->data_sql->user_attrs->flag_values;
     $q = "delete from " . $t_name . " \n\t\t      where " . $c->uid . "  = '" . $uid . "'";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             return true;
         } else {
             ErrorHandler::log_errors($res);
             return false;
         }
     }
     return true;
 }
 /**
  *	get all versions of file specific for domain
  *
  *  Possible options parameters:
  *		none
  *
  *	@param string $did		domain id
  *	@param string $file		filename (with path)
  *	@param array $opt		associative array of options
  *	@return array			array of versions of file or FALSE on failure
  */
 function get_file_versions($did, $file, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain_settings->table_name;
     /* col names */
     $cd =& $config->data_sql->domain_settings->cols;
     /* flags */
     $fd =& $config->data_sql->domain_settings->flag_values;
     $q = "select " . $cd->version . ", " . $cd->timestamp . ", " . $cd->flags . " \n\t\t      from " . $td_name . " \n\t\t\t  where " . $cd->did . " = " . $this->sql_format($did, "s") . " and\n\t\t\t        " . $cd->filename . " = " . $this->sql_format($file, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out[$row[$cd->version]]['timestamp'] = $row[$cd->timestamp];
         $out[$row[$cd->version]]['deleted'] = (bool) ($row[$cd->flags] & $fd["DB_DELETED"]);
         $out[$row[$cd->version]]['dir'] = (bool) ($row[$cd->flags] & $fd["DB_DIR"]);
     }
     $res->free();
     return $out;
 }
 /**
  *	get content of file specific for a domain from db
  *
  *  Possible options parameters:
  *		none
  *
  *	@param string $did		domain id
  *	@param string $file		filename (with path)
  *	@param string $version	version of file
  *	@param array $opt		associative array of options
  *	@return string			content of file or FALSE on failure
  */
 function get_file_content($did, $file, $version, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain_settings->table_name;
     /* col names */
     $cd =& $config->data_sql->domain_settings->cols;
     $q = "select " . $cd->content . " \n\t\t      from " . $td_name . " \n\t\t\t  where " . $cd->did . " = " . $this->sql_format($did, "s") . " and\n\t\t\t        " . $cd->filename . " = " . $this->sql_format($file, "s") . " and\n\t\t\t        " . $cd->version . " = " . $this->sql_format($version, "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = null;
     if ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out = $this->sql_unescape_binary($row[$cd->content]);
     }
     $res->free();
     return $out;
 }
 function check_credentials($uname, $did, $realm, $passw, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_ldap($errors)) {
         ErrorHandler::add_error($errors);
         return 0;
     }
     $a =& $config->auth_ldap['attrib'];
     $q = array("(" . $a['user'] . "=" . addslashes($user . '@' . $domain) . ") ", 'base_dn' => $config->auth_ldap['dn'], 'attributes' => array($a['uuid'], $a['pass']), 'action' => 'list');
     $res = $this->ldap->query($q);
     if (DB::isError($res)) {
         //if user is not found
         if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             return -1;
         } else {
             ErrorHandler::log_errors($res);
             return 0;
         }
     }
     $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
     $res->free();
     // check password
     if ($row[$a['pass']] != $passw) {
         return -1;
     }
     return $row[$a['uuid']];
 }
 function get_missed_calls_of_yesterday($uid, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     if ($this->db_host['parsed']['phptype'] == 'mysql') {
         $q_date = " date_format(request_timestamp, '%Y-%m-%d')=date_format(DATE_SUB(CURDATE(), INTERVAL 1 DAY), '%Y-%m-%d') ";
     } else {
         $q_date = " date_trunc('day', request_timestamp)=date_trunc('day', (CURRENT_DATE - INTERVAL '1 DAY')) ";
     }
     $q = "SELECT from_uri, sip_from, request_timestamp, sip_status  " . "FROM " . $config->data_sql->table_missed_calls . " " . "WHERE to_uid='" . $uid . "' and " . $q_date . "ORDER BY request_timestamp DESC ";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $out[] = $row;
     }
     $res->free();
     return $out;
 }
 /**
  * return list of all attributes without atribute named as $att_edit
  * $att_edit may be null
  */
 function get_attr_type_groups($opt = null)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_at =& $config->data_sql->attr_types->table_name;
     /* col names */
     $c =& $config->data_sql->attr_types->cols;
     $q = "select " . $c->group . "\n\t\t    from " . $t_at . " \n\t\t\tgroup by " . $c->group;
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out[] = $row[$c->group];
     }
     $res->free();
     return $out;
 }
 /**
  *  Enable or disable domain
  *
  *  Possible options:
  *
  *    did		(int)   	default: null
  *      id of domain which will be en/disabled
  *      this option is REQUIRED
  *      
  *    disable	(bool)  	default: false
  *      if true domain will be disabled, otherwise wil be enabled
  *      
  *	@param array $opt		associative array of options
  *	@return bool			TRUE on success, FALSE on failure
  */
 function enable_domain($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain->table_name;
     /* col names */
     $cd =& $config->data_sql->domain->cols;
     /* flags */
     $fd =& $config->data_sql->domain->flag_values;
     $o_did = isset($opt['did']) ? $opt['did'] : null;
     $o_disable = isset($opt['disable']) ? $opt['disable'] : false;
     if (is_null($o_did)) {
         ErrorHandler::log_errors(PEAR::raiseError('domain for en/disable is not specified'));
         return false;
     }
     $q = "update " . $td_name . " set ";
     if ($o_disable) {
         $q .= $cd->flags . " = " . $cd->flags . " | " . $fd['DB_DISABLED'];
     } else {
         $q .= $cd->flags . " = " . $cd->flags . " & ~" . $fd['DB_DISABLED'];
     }
     $q .= " where " . $cd->did . " = " . $this->sql_format($o_did, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
Exemplo n.º 9
0
 /**
  *	delete alias of user
  *
  *	@param string	$uid		owner of the contact 
  *	@param string	$username	username part from URI
  *	@param string	$did		domain part from URI
  *	@param string	$flags		flags of the URI
  *	@param array	$opt		various options
  *	@return bool				TRUE on success, FALSE on failure
  */
 function delete_uri($uid, $scheme, $username, $did, $flags, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table name */
     $t_name =& $config->data_sql->uri->table_name;
     /* col names */
     $c =& $config->data_sql->uri->cols;
     /* flags */
     $f =& $config->data_sql->uri->flag_values;
     $q = "delete from " . $t_name . "\n\t\t      where " . $c->uid . "      = " . $this->sql_format($uid, "s") . " and \n\t\t            " . $c->scheme . "   = " . $this->sql_format($scheme, "s") . " and \n\t\t            " . $c->username . " = " . $this->sql_format($username, "s") . " and \n\t\t            " . $c->did . "      = " . $this->sql_format($did, "s") . " and \n\t\t            " . $c->flags . "    = " . $this->sql_format($flags, "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     if (isModuleLoaded('xxl')) {
         // get domain: $alias_d = domainname of $did
         $alias_uri = "sip:" . $username . "@" . $alias_d;
         if (false === $this->clear_proxy_xxl($alias_uri, null, $errors)) {
             ErrorHandler::add_error($errors);
             return false;
         }
     }
     return true;
 }
 /**
  *  Get array of aliases of user with given sip-uri
  *
  *  Possible options:
  *		none
  *
  *	@param	string	$sip_uri	URI of user
  *	@param	array	$opt		array of options
  *	@return	array				FALSE on error
  */
 function get_aliases_by_uri($sip_uri, $opt)
 {
     global $config;
     $errors = array();
     /* create connection to proxy where are stored data of user */
     if (isModuleLoaded('xxl') and $this->name != "get_aliases_tmp") {
         $tmp_data = CData_Layer::singleton("get_aliases_tmp", $errors);
         $tmp_data->set_xxl_user_id($sip_uri);
         $tmp_data->expect_user_id_may_not_exists();
         return $tmp_data->get_aliases_by_uri($sip_uri, $errors);
     }
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $tu_name =& $config->data_sql->uri->table_name;
     /* col names */
     $cu =& $config->data_sql->uri->cols;
     /* flags */
     $fu =& $config->data_sql->uri->flag_values;
     //parse username and domain from sip uri
     $reg =& Creg::singleton();
     $uname = $reg->get_username($sip_uri);
     $realm = $reg->get_domainname($sip_uri);
     if (!$uname or !$realm) {
         return array();
     }
     if ($config->multidomain) {
         if (false === ($did = $this->get_did_by_realm($realm, null))) {
             return false;
         }
         if (is_null($did)) {
             return array();
         }
     } else {
         $did = $config->default_did;
     }
     $flags_val = $fu['DB_DISABLED'] | $fu['DB_DELETED'];
     $q = "select " . $cu->uid . " as uid\n\t\t    from " . $tu_name . "\n\t\t\twhere  " . $cu->did . "      = " . $this->sql_format($did, "s") . " and \n\t\t\t       " . $cu->username . " = " . $this->sql_format($uname, "s") . " and \n\t\t\t\t  (" . $cu->flags . " & " . $flags_val . ") = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
     if (!$row) {
         unset($res);
         return array();
     }
     $uid = $row['uid'];
     if (is_null($uid)) {
         return array();
     }
     $uri_handler =& URIs::singleton($uid);
     if (false === ($out = $uri_handler->get_URIs())) {
         return false;
     }
     return $out;
 }
 /**
  *  Delete credentials from DB
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - none
  *	
  *
  *	@return bool
  */
 function del_credentials($uid, $did, $uname, $realm, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table name */
     $t_name =& $config->data_sql->credentials->table_name;
     /* col names */
     $c =& $config->data_sql->credentials->cols;
     /* flags */
     $f =& $config->data_sql->credentials->flag_values;
     $q = "delete from " . $t_name . "\n\t\t      where " . $c->uid . "   = " . $this->sql_format($uid, "s") . " and\n\t\t            " . $c->uname . " = " . $this->sql_format($uname, "s") . " and\n\t\t            " . $c->realm . " = " . $this->sql_format($realm, "s");
     if ($config->auth['use_did']) {
         $q .= " and " . $c->did . " = " . $this->sql_format($did, "s");
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
Exemplo n.º 12
0
 /**
  *  Purge old acc records
  *
  *  Possible options parameters:
  *		none
  *
  *	@param array $opt		associative array of options
  *	@return bool			TRUE on success, FALSE on failure
  */
 function delete_acc($opt)
 {
     global $config;
     if (!$config->keep_acc_interval) {
         return true;
     }
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return 0;
     }
     /* table's name */
     $t_name =& $config->data_sql->acc->table_name;
     /* col names */
     $c =& $config->data_sql->acc->cols;
     /* flags */
     $f =& $config->data_sql->acc->flag_values;
     if ($this->db_host['parsed']['phptype'] == 'mysql') {
         $q = "delete from " . $t_name . " \n\t\t\t\twhere DATE_ADD(" . $c->request_timestamp . ", INTERVAL " . $config->keep_acc_interval . " DAY) < now()";
     } else {
         $q = "delete from " . $t_name . " \n\t\t\t\twhere (" . $c->request_timestamp . " + INTERVAL '" . $config->keep_acc_interval . " DAY') < now()";
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         //expect that table mayn't exist in installed version
         if ($res->getCode() != DB_ERROR_NOSUCHTABLE) {
             ErrorHandler::log_errors($res);
             return false;
         }
     }
     return true;
 }
 /**
  *  return array of credentials of user
  *
  *  Possible options:
  *	 - none
  *    	
  *	@param	string	$uid	uid of user
  *	@param	array	$opt	array of options
  *	@return array			array of credentials
  */
 function get_credentials($uid, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_name =& $config->data_sql->credentials->table_name;
     /* col names */
     $c =& $config->data_sql->credentials->cols;
     /* flags */
     $f =& $config->data_sql->credentials->flag_values;
     $q = "select " . $c->did . ", \n\t\t           " . $c->uname . ",\n\t\t           " . $c->realm . ",\n\t\t           " . $c->password . ",\n\t\t           " . $c->ha1 . ",\n\t\t           " . $c->ha1b . ",\n\t\t           " . $c->flags . "\n\t\t    from " . $t_name . " \n\t\t\twhere " . $c->uid . " = " . $this->sql_format($uid, "s") . " and\n\t\t\t      " . $c->flags . " & " . $f['DB_DELETED'] . " = 0\n\t\t\torder by " . $c->realm . ", " . $c->uname;
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i] = new Credential($uid, $row[$c->did], $row[$c->uname], $row[$c->realm], $row[$c->password], $row[$c->ha1], $row[$c->ha1b], $row[$c->flags]);
     }
     $res->free();
     return $out;
 }
 /**
  *  return array of domain ids which can administer given user
  *
  *
  *  Possible options:
  *	 - none
  *      
  *	@param string $uid		
  *	@param array $opt		associative array of options
  *	@return array			array of domain ids or FALSE on error
  */
 function get_domains_of_admin($uid, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_name =& $config->data_sql->domain_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->domain_attrs->cols;
     /* flags */
     $f =& $config->data_sql->domain_attrs->flag_values;
     $an =& $config->attr_names;
     $q = "select " . $c->did . " \n\t\t    from " . $t_name . "\n\t\t\twhere  " . $c->name . "  = '" . $an['admin'] . "' and \n\t\t\t       " . $c->value . " = " . $this->sql_format($uid, "s") . " and \n\t\t\t      (" . $c->flags . " & " . $f['DB_DELETED'] . ") = 0 and\n\t\t\t\t  (" . $c->flags . " & " . $f['DB_FOR_SERWEB'] . ") = " . $f['DB_FOR_SERWEB'];
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i] = $row[$c->did];
     }
     $res->free();
     return $out;
 }
 /**
  *  return flags of domain with given domain ID as associative array
  *
  *  Keys of associative arrays:
  *   - disabled
  *   - deleted
  *
  *  Possible options:
  *	 - none
  *
  *	@param string $did		domain ID
  *	@param array $opt		associative array of options
  *	@return array			domain flags or FALSE on error
  */
 function get_domain_flags($did, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain->table_name;
     /* col names */
     $cd =& $config->data_sql->domain->cols;
     /* flags */
     $fd =& $config->data_sql->domain->flag_values;
     $q = "select " . $cd->flags . "\n\t\t    from " . $td_name . "\n\t\t\twhere " . $cd->did . "=" . $this->sql_format($did, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $disabled = true;
     $deleted = true;
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $disabled = ($disabled and $row[$cd->flags] & $fd['DB_DISABLED']);
         $deleted = ($deleted and $row[$cd->flags] & $fd['DB_DELETED']);
     }
     $res->free();
     return array('disabled' => $disabled, 'deleted' => $deleted);
 }
 /**
  * delete all missed calls of user
  * if $timestamp is not null delete only calls older than $timestamp
  */
 function delete_user_missed_calls($uid, $timestamp)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_mc =& $config->data_sql->missed_calls->table_name;
     /* flags */
     $f_mc =& $config->data_sql->missed_calls->flag_values;
     $q = "delete from " . $t_mc . " \n\t\t\twhere to_uid='" . $uid . "'";
     if (!is_null($timestamp)) {
         $q .= " and request_timestamp < '" . gmdate("Y-m-d H:i:s", $timestamp) . "'";
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             return true;
         } else {
             ErrorHandler::log_errors($res);
             return false;
         }
     }
     return true;
 }
 /**
  *  return new id for a user
  *
  *  Possible options:
  *	 - none
  *      
  *	@param array $opt		associative array of options
  *	@return int				new id or FALSE on error
  */
 function get_new_user_id($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $tc_name =& $config->data_sql->credentials->table_name;
     $ta_name =& $config->data_sql->user_attrs->table_name;
     /* col names */
     $cc =& $config->data_sql->credentials->cols;
     $ca =& $config->data_sql->user_attrs->cols;
     /* flags */
     $fc =& $config->data_sql->credentials->flag_values;
     $fa =& $config->data_sql->user_attrs->flag_values;
     $q = "select max(" . $this->get_sql_cast_to_int_funct($cc->uid) . ")\n\t\t    from " . $tc_name . "\n\t\t\twhere " . $this->get_sql_regex_match("^[0-9]+\$", $cc->uid, null);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row1 = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $res->free();
     $q = "select max(" . $this->get_sql_cast_to_int_funct($ca->uid) . ")\n\t\t    from " . $ta_name . "\n\t\t\twhere " . $this->get_sql_regex_match("^[0-9]+\$", $ca->uid, null);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row2 = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $res->free();
     return max($row1[0], $row2[0]) + 1;
 }
Exemplo n.º 18
0
 /**
  *  Update URI table
  *
  *  Possible options:
  *	 - none
  *	
  *	@param	array	$values
  *	@param	array	$filter
  *	@param	array	$opt
  *	@return bool			FALSE on error, TRUE otherwise
  */
 function update_uri($values, $filter, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table name */
     $t_name =& $config->data_sql->uri->table_name;
     /* col names */
     $c =& $config->data_sql->uri->cols;
     /* flags */
     $f =& $config->data_sql->uri->flag_values;
     $an =& $config->attr_names;
     $qw = "";
     if (isset($filter['scheme'])) {
         $qw .= $c->scheme . "   = " . $this->sql_format($filter['scheme'], "s") . " and ";
     }
     if (isset($filter['uid'])) {
         $qw .= $c->uid . "      = " . $this->sql_format($filter['uid'], "s") . " and ";
     }
     if (isset($filter['did'])) {
         $qw .= $c->did . "      = " . $this->sql_format($filter['did'], "s") . " and ";
     }
     if (isset($filter['username'])) {
         $qw .= $c->username . " = " . $this->sql_format($filter['username'], "s") . " and ";
     }
     if (isset($filter['flags'])) {
         $qw .= $c->flags . "    = " . $this->sql_format($filter['flags'], "s") . " and ";
     }
     $qw .= $this->get_sql_bool(true);
     $qs = array();
     if (isset($values['scheme'])) {
         $qs[] = $c->scheme . "   = " . $this->sql_format($values['scheme'], "s");
     }
     if (isset($values['uid'])) {
         $qs[] = $c->uid . "      = " . $this->sql_format($values['uid'], "s");
     }
     if (isset($values['did'])) {
         $qs[] = $c->did . "      = " . $this->sql_format($values['did'], "s");
     }
     if (isset($values['username'])) {
         $qs[] = $c->username . " = " . $this->sql_format($values['username'], "s");
     }
     if (isset($values['flags'])) {
         $qs[] = $c->flags . "    = " . $this->sql_format($values['flags'], "n");
     }
     $qs = implode(", ", $qs);
     $q = "update " . $t_name . " \n\t\t      set " . $qs . "\n\t\t      where " . $qw;
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
 /**
  *  Delete credentials from DB
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - none
  *
  *	@param	string		$uid
  *	@param	string		$did
  *	@param	string		$uname
  *	@param	string		$realm
  *	@param	Credential	$new_vals
  *	@param	array		$opt
  *	@return bool
  */
 function update_credentials($uid, $did, $uname, $realm, $new_vals, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table name */
     $t_name =& $config->data_sql->credentials->table_name;
     /* col names */
     $c =& $config->data_sql->credentials->cols;
     /* flags */
     $f =& $config->data_sql->credentials->flag_values;
     $set = array();
     if ($new_vals->did_changed()) {
         $set[] = $c->did . " = " . $this->sql_format($new_vals->get_did(), "s");
     }
     if ($new_vals->uname_changed()) {
         $set[] = $c->uname . " = " . $this->sql_format($new_vals->get_uname(), "s");
     }
     if ($new_vals->realm_changed()) {
         $set[] = $c->realm . " = " . $this->sql_format($new_vals->get_realm(), "s");
     }
     if ($new_vals->password_changed()) {
         if ($config->clear_text_pw) {
             $set[] = $c->password . " = " . $this->sql_format($new_vals->get_password(), "s");
         } else {
             $set[] = $c->password . " = " . $this->sql_format("", "s");
         }
     }
     if ($new_vals->ha1_changed()) {
         $set[] = $c->ha1 . " = " . $this->sql_format($new_vals->get_ha1(), "s");
         $set[] = $c->ha1b . " = " . $this->sql_format($new_vals->get_ha1b(), "s");
     }
     if ($new_vals->flags_changed()) {
         $set[] = $c->flags . " = " . $this->sql_format($new_vals->get_flags(), "s");
     }
     if (!count($set)) {
         return true;
     }
     // nothing to change
     $q = "update " . $t_name . "\n\t\t\t  set\t" . implode(", ", $set) . "\n\t\t      where " . $c->uid . "   = " . $this->sql_format($uid, "s") . " and\n\t\t            " . $c->uname . " = " . $this->sql_format($uname, "s") . " and\n\t\t            " . $c->realm . " = " . $this->sql_format($realm, "s");
     if ($config->auth['use_did']) {
         $q .= " and " . $c->did . " = " . $this->sql_format($did, "s");
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
Exemplo n.º 20
0
 function get_IMs($uid)
 {
     global $config, $sess;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     $t_name =& $config->data_sql->msg_silo->table_name;
     /* table's name */
     $c =& $config->data_sql->msg_silo->cols;
     /* col names */
     /* get num rows */
     $q = "select count(*) from " . $t_name . "\n\t\t    where " . $c->uid . " = " . $this->sql_format($uid, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $this->set_num_rows($row[0]);
     $res->free();
     /* if act_row is bigger then num_rows, correct it */
     $this->correct_act_row();
     $q = "select " . $c->mid . ", " . $c->from . ", " . $c->inc_time . ", " . $c->body . " \n\t\t    from " . $t_name . " where " . $c->uid . " = " . $this->sql_format($uid, "s") . $this->get_sql_limit_phrase();
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $timestamp = gmmktime(substr($row[$c->inc_time], 11, 2), substr($row[$c->inc_time], 14, 2), substr($row[$c->inc_time], 17, 2), substr($row[$c->inc_time], 5, 2), substr($row[$c->inc_time], 8, 2), substr($row[$c->inc_time], 0, 4));
         //year
         if (date('Y-m-d', $timestamp) == date('Y-m-d')) {
             $time = "today " . date('H:i', $timestamp);
         } else {
             $time = date('Y-m-d H:i', $timestamp);
         }
         $out[$i]['src_addr'] = htmlspecialchars($row[$c->from]);
         $out[$i]['raw_src_addr'] = $row[$c->from];
         $out[$i]['mid'] = $row[$c->mid];
         $out[$i]['time'] = $time;
         $out[$i]['timestamp'] = $timestamp;
         $out[$i]['body'] = $row[$c->body];
         $out[$i]['url_reply'] = $sess->url("send_im.php?kvrk=" . uniqid("") . "&sip_addr=" . rawURLEncode($row[$c->from]));
         $out[$i]['url_dele'] = $sess->url("message_store.php?kvrk=" . uniqid("") . "&dele_im=" . rawURLEncode($row[$c->mid]));
     }
     $res->free();
     return $out;
 }
 /**
  *  Function return IDs of domains marked as deleted
  *
  *
  *  Possible options parameters:
  *
  *	  deleted_before (int)	default:null
  *		if is set, only domains marked as deleted before given timestamp are returned
  *  
  *	@return array	array of domain IDs or FALSE on error
  */
 function get_deleted_domains($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $ta_name =& $config->data_sql->domain_attrs->table_name;
     $td_name =& $config->data_sql->domain->table_name;
     /* col names */
     $ca =& $config->data_sql->domain_attrs->cols;
     $cd =& $config->data_sql->domain->cols;
     /* flags */
     $fa =& $config->data_sql->domain_attrs->flag_values;
     $fd =& $config->data_sql->domain->flag_values;
     $an =& $config->attr_names;
     $opt_deleted_before = isset($opt['deleted_before']) ? $opt['deleted_before'] : null;
     $q1_w = $q2_w = "";
     if (!is_null($opt_deleted_before)) {
         /* get users deleted before given timestamp */
         $o = array("name" => $an['deleted_ts']);
         if (false === ($attrs = $this->get_attr_by_val('domain', $o))) {
             return false;
         }
         $dids = array();
         foreach ($attrs as $v) {
             if ((int) $v['value'] < (int) $opt_deleted_before) {
                 $dids[] = $v['id'];
             }
         }
         $q1_w = " and " . $this->get_sql_in("dom." . $cd->did, $dids, true);
         $q2_w = " and " . $this->get_sql_in("at." . $ca->did, $dids, true);
     }
     $q1 = "select dom." . $cd->did . " as did\n\t\t\t  from " . $td_name . " dom \n\t\t\t  where (dom." . $cd->flags . " & " . $fd['DB_DELETED'] . ") = " . $fd['DB_DELETED'] . $q1_w . " \n\t\t\t  group by dom." . $cd->did;
     $q2 = "select at." . $ca->did . " as did\n\t\t\t  from " . $ta_name . " at \n\t\t\t  where (at." . $ca->flags . " & " . $fa['DB_DELETED'] . ") = " . $fa['DB_DELETED'] . $q2_w . " \n\t\t\t  group by at." . $ca->did;
     $q = "(" . $q1 . ") union (" . $q2 . ")";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out[] = $row['did'];
     }
     $res->free();
     return $out;
 }
 /**
  *  return array of associtive arrays containig domain names
  *
  *  Keys of associative arrays:
  *   - id
  *   - name
  *
  *  Possible options:
  *	 - order_by	(string) - name of column for sorting. If false or empty, 
  *	                       result is not sorted (default: 'name')
  *	 - order_desc (bool) - order descending (default: false)
  *	 - filter    (array) - associative array of pairs (column, value) which 
  *	                       should be returned (default: array)
  *	 - check_deleted_flag (bool) - If true, domains marked as deleted 
  *	                               are not returned (default:true)
  *
  *	@param array $opt		associative array of options
  *	@return array			array of domain names or FALSE on error
  */
 function get_domain($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain->table_name;
     /* col names */
     $cd =& $config->data_sql->domain->cols;
     /* flags */
     $fd =& $config->data_sql->domain->flag_values;
     $o_filter = isset($opt['filter']) ? $opt['filter'] : array();
     $o_order_by = isset($opt['order_by']) ? $opt['order_by'] : "name";
     $o_order_desc = isset($opt['order_desc']) ? "desc" : "";
     $o_check_deleted = isset($opt['check_deleted_flag']) ? $opt['check_deleted_flag'] : true;
     $qw = $this->sql_format(true, "b");
     foreach ($o_filter as $k => $v) {
         $qw .= " and " . $cd->{$k} . " = " . $this->sql_format($v, "s");
     }
     $q_deleted = "";
     if ($o_check_deleted) {
         $q_deleted = " and (" . $cd->flags . " & " . $fd['DB_DELETED'] . ") = 0 ";
     }
     $q = "select " . $cd->did . ", \n\t\t           " . $cd->name . ", \n\t\t\t       " . $cd->flags . " & " . $fd['DB_DISABLED'] . " as disabled,\n\t\t\t       " . $cd->flags . " & " . $fd['DB_CANON'] . " as canon\n\t\t    from " . $td_name . "\n\t\t\twhere " . $qw . $q_deleted;
     if ($o_order_by) {
         if (isset($cd->{$o_order_by})) {
             $q .= " order by " . $cd->{$o_order_by} . " " . $o_order_desc;
         } else {
             $q .= " order by " . $o_order_by . " " . $o_order_desc;
         }
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i]['did'] = $row[$cd->did];
         $out[$i]['name'] = $row[$cd->name];
         $out[$i]['disabled'] = $row['disabled'];
         $out[$i]['canon'] = $row['canon'];
         $out[$i]['primary_key'] = array('did' => &$out[$i]['did'], 'name' => &$out[$i]['name']);
     }
     $res->free();
     return $out;
 }
 /**
  *	delete all records of user from speed_dial table
  */
 function delete_user_speed_dial($uid)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_name =& $config->data_sql->speed_dial->table_name;
     $ta_name =& $config->data_sql->sd_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->speed_dial->cols;
     $ca =& $config->data_sql->sd_attrs->cols;
     $q = "select " . $c->id . " as id from " . $t_name . " where " . $c->uid . " = '" . $uid . "'";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             return true;
         } else {
             ErrorHandler::log_errors($res);
             return false;
         }
     }
     $ids = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $ids[] = $row['id'];
     }
     if (count($ids)) {
         $q = "delete from " . $ta_name . " where " . $this->get_sql_in($ca->id, $ids);
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             } else {
                 ErrorHandler::log_errors($res);
                 return false;
             }
         }
     }
     $q = "delete from " . $t_name . " where " . $c->uid . " = '" . $uid . "'";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
 /**
  *	get latest versions of files specific for domain
  *
  *  Possible options parameters:
  *		none
  *
  *	@param string $did		domain id
  *	@param array $opt		associative array of options
  *	@return array			array of versions of file or FALSE on failure
  */
 function get_latest_file_versions($did, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain_settings->table_name;
     /* col names */
     $cd =& $config->data_sql->domain_settings->cols;
     /* flags */
     $fd =& $config->data_sql->domain_settings->flag_values;
     /* 
     	clean solution but unfortunately not working in mysql 4.0
     	
     			$q = "select ds.".$cd->filename.", ds.".$cd->version." as ver, ds.".$cd->flags." 
     			      from ".$td_name." ds join (
     				      select ".$cd->filename.", max(".$cd->version.") as ver
     				      from ".$td_name."
     				      where ".$cd->did." = ".$this->sql_format($did, "s")."
     				      group by ".$cd->filename."
     				  ) v on (ds.".$cd->filename." = v.".$cd->filename." and
     				          ds.".$cd->version." = v.ver)
     				  where ds.".$cd->did." = ".$this->sql_format($did, "s")." 
     				  group by ds.".$cd->filename;
     */
     /* This query return multiple rows for each file. Ordering row by 
     		   version is important because older versions are replaced by newest
     		   in output array.
     		 */
     $q = "select " . $cd->filename . ", " . $cd->flags . ", max(" . $cd->version . ") as ver \n\t\t      from " . $td_name . " \n\t\t\t  where " . $cd->did . " = " . $this->sql_format($did, "s") . " \n\t\t\t  group by " . $cd->filename . ", " . $cd->flags . "\n\t\t\t  order by ver";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out[$row[$cd->filename]]['version'] = $row['ver'];
         $out[$row[$cd->filename]]['deleted'] = (bool) ($row[$cd->flags] & $fd["DB_DELETED"]);
         $out[$row[$cd->filename]]['dir'] = (bool) ($row[$cd->flags] & $fd["DB_DIR"]);
     }
     $res->free();
     return $out;
 }
 /**
  *  Get array of uids asociated with given uri
  *
  *  Possible options:
  *	 - none
  *
  *	@param	string	$sip_uri	URI of user
  *	@param	array	$opt		array of options
  *	@return	array				FALSE on error
  */
 function get_uid_of_uri($sip_uri, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $tu_name =& $config->data_sql->uri->table_name;
     /* col names */
     $cu =& $config->data_sql->uri->cols;
     /* flags */
     $fu =& $config->data_sql->uri->flag_values;
     //parse username and domain from sip uri
     $reg =& Creg::singleton();
     $uname = $reg->get_username($sip_uri);
     $realm = $reg->get_domainname($sip_uri);
     if (!$uname or !$realm) {
         return array();
     }
     if ($config->multidomain) {
         if (false === ($did = $this->get_did_by_realm($realm, null))) {
             return false;
         }
         if (is_null($did)) {
             return array();
         }
     } else {
         $did = $config->default_did;
     }
     $flags_val = $fu['DB_DISABLED'] | $fu['DB_DELETED'];
     $q = "select " . $cu->uid . " as uid,\n\t\t           " . $cu->flags . " as flags\n\t\t    from " . $tu_name . "\n\t\t\twhere  " . $cu->did . "      = " . $this->sql_format($did, "s") . " and \n\t\t\t       " . $cu->username . " = " . $this->sql_format($uname, "s") . " and \n\t\t\t\t  (" . $cu->flags . " & " . $flags_val . ") = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i]['uid'] = $row['uid'];
         $out[$i]['is_to'] = (bool) ($row['flags'] & $fu['DB_IS_TO']);
         $out[$i]['is_from'] = (bool) ($row['flags'] & $fu['DB_IS_FROM']);
     }
     return $out;
 }
Exemplo n.º 26
0
 /**
  *  Add new URI to DB
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - disabled	(bool) - set flag disabled (default: false)
  *	 - canon	(bool) - set flag canonical (default: false)
  *	 - flags	(int)  - Set value of flags directly. If is set, options 
  *	                     'canon' and 'disabled' are ignored. (default: null)
  *
  *	@return bool
  */
 function add_uri($uid, $scheme, $uname, $did, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table name */
     $t_name =& $config->data_sql->uri->table_name;
     /* col names */
     $c =& $config->data_sql->uri->cols;
     /* flags */
     $f =& $config->data_sql->uri->flag_values;
     $an =& $config->attr_names;
     /* set default values for options */
     $opt_disabled = isset($opt["disabled"]) ? (bool) $opt["disabled"] : false;
     $opt_canon = isset($opt["canon"]) ? (bool) $opt["canon"] : false;
     $opt_flags = isset($opt["flags"]) ? $opt["flags"] : null;
     if (!is_null($opt_flags)) {
         $flags = $opt_flags;
     } else {
         $ga =& Global_attrs::singleton();
         if (false === ($flags = $ga->get_attribute($an['uri_default_flags']))) {
             return false;
         }
         if (!is_numeric($flags)) {
             ErrorHandler::log_errors(PEAR::raiseError("Global attribute '" . $an['uri_default_flags'] . "' is not defined or is not a number Can't create URI."));
             return false;
         }
         if ($opt_disabled) {
             $flags = $flags | $f['DB_DISABLED'];
         }
         if ($opt_canon) {
             $flags = $flags | $f['DB_CANON'];
         }
     }
     $q = "insert into " . $t_name . "(\n\t             " . $c->uid . ", " . $c->scheme . ", " . $c->username . ", " . $c->did . ", " . $c->flags . ")\n\t\t      values (" . $this->sql_format($uid, "s") . ", \n\t\t\t          " . $this->sql_format($scheme, "s") . ", \n\t\t\t          " . $this->sql_format($uname, "s") . ", \n\t\t\t\t\t  " . $this->sql_format($did, "s") . ", \n\t\t\t\t\t  " . $this->sql_format($flags, "n") . ")";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
 /**
  *  Get values of global attributes
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - none
  *
  *	@return array
  */
 function get_global_attrs($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_name =& $config->data_sql->global_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->global_attrs->cols;
     /* flags */
     $f =& $config->data_sql->global_attrs->flag_values;
     $out = array();
     $errors = array();
     /*
      *	get global_attrs
      */
     $flags_val = $f['DB_FOR_SERWEB'];
     $q = "select " . $c->name . " as name,\n\t\t           " . $c->value . " as value \n\t\t    from " . $t_name . "\n\t\t\twhere (" . $c->flags . " & " . $flags_val . ") = " . $flags_val;
     if (isset($c->order)) {
         $q .= " order by " . $c->name . ", " . $c->order;
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         ErrorHandler::add_error($errors);
         return false;
     }
     $ats =& Attr_types::singleton();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         if (false === ($at =& $ats->get_attr_type($row['name']))) {
             return false;
         }
         if (is_object($at) and $at->is_multivalue()) {
             $out[$row['name']][] = $row['value'];
         } else {
             $out[$row['name']] = $row['value'];
         }
     }
     $res->free();
     return $out;
 }
Exemplo n.º 28
0
 function &get_timezones()
 {
     static $timezones = null;
     global $data;
     if (!is_null($timezones)) {
         return $timezones;
     }
     $errors = array();
     $data->add_method('get_time_zones');
     $tz = $data->get_time_zones($errors);
     if (count($errors)) {
         ErrorHandler::add_error($errors);
         $out = false;
         //Only variable references should be returned
         return $out;
     }
     $timezones =& $tz;
     return $timezones;
 }
 /**
  *	delete file specific for a domain from db
  *
  *  Possible options parameters:
  *		none
  *
  *	@param string $did		domain id
  *	@param string $file		filename (with path)
  *	@param string $version	version of file
  *	@param array $opt		associative array of options
  *	@return bool			TRUE on success or FALSE on failure
  */
 function del_file_version($did, $file, $version, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain_settings->table_name;
     /* col names */
     $cd =& $config->data_sql->domain_settings->cols;
     $q = "delete from " . $td_name . " \n\t\t\t  where " . $cd->did . " = " . $this->sql_format($did, "s") . " and\n\t\t\t        " . $cd->filename . " = " . $this->sql_format($file, "s") . " and\n\t\t\t        " . $cd->version . " = " . $this->sql_format($version, "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
 /**
  *  Update attribute type group
  *
  *  On error this method returning FALSE.
  *
  *  Possible options:
  *   - none
  *  
  *  @param  string      $old_group_name   Name of group to rename
  *  @param  string      $new_group_name   New name for the group
  *  @param  array       $opt        Array of options
  *  @return bool
  */
 function rename_attr_type_group($old_group_name, $new_group_name, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_name =& $config->data_sql->attr_types->table_name;
     /* col names */
     $c =& $config->data_sql->attr_types->cols;
     $q = "update " . $t_name . " \n              set   " . $c->group . " = " . $this->sql_format($new_group_name, "s") . "\n              where " . $c->group . " = " . $this->sql_format($old_group_name, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }