function ilMDConvert($table, $fields, $key)
{
    global $ilDB;
    $where = "WHERE ";
    $where .= implode(" LIKE '%\\%' ESCAPE '�' OR ", ilUtil::quoteArray($fields));
    $where .= " LIKE '%\\%' ESCAPE '�'";
    $query = "SELECT * FROM " . $table . " " . $where;
    $res = $ilDB->query($query);
    while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
        $query = "UPDATE {$table} ";
        $counter = 0;
        foreach ($fields as $field) {
            if ($counter++) {
                $query .= ", ";
            } else {
                $query .= "SET ";
            }
            $query .= $field . " = " . $ilDB->quote(stripslashes($row->{$field})) . " ";
        }
        $query .= " WHERE " . $key . " = " . $ilDB->quote($row->{$key});
        // Perform the query
        $ilDB->query($query);
    }
}
 /**
  * get child nodes of given node by object type
  * @access	public
  * @param	integer		node_id
  * @param	array		array of object type
  * @return	array		with node data of all childs or empty array
  */
 public function getChildsByTypeFilter($a_node_id, $a_types)
 {
     global $ilDB;
     if (!isset($a_node_id) or !$a_types) {
         $message = get_class($this) . "::getChildsByType(): Missing parameter! node_id:" . $a_node_id . " type:" . $a_types;
         $this->ilErr->raiseError($message, $this->ilErr->WARNING);
     }
     $filter = ' ';
     if ($a_types) {
         $filter = 'AND ' . $this->table_obj_data . '.type IN(' . implode(',', ilUtil::quoteArray($a_types)) . ') ';
     }
     $query = 'SELECT * FROM ' . $this->table_tree . ' ' . $this->buildJoin() . 'WHERE parent = ' . $ilDB->quote($a_node_id, 'integer') . ' ' . 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = ' . $ilDB->quote($this->tree_id, 'integer') . ' ' . $filter . 'ORDER BY ' . $this->table_tree . '.lft';
     $res = $ilDB->query($query);
     while ($row = $ilDB->fetchAssoc($res)) {
         $childs[] = $this->fetchNodeData($row);
     }
     return $childs ? $childs : array();
 }
 /**
  * Function that sorts ids by a given table field using WHERE IN
  * E.g: __sort(array(6,7),'usr_data','lastname','usr_id') => sorts by lastname
  *
  * @param array Array of ids
  * @param string table name
  * @param string table field
  * @param string id name
  * @return array sorted ids
  *
  * @access protected
  * @static
  * 
  */
 public static function _sortIds($a_ids, $a_table, $a_field, $a_id_name)
 {
     global $ilDB;
     if (!$a_ids) {
         return array();
     }
     // use database to sort user array
     $where = "WHERE " . $a_id_name . " IN (";
     $where .= implode(",", ilUtil::quoteArray($a_ids));
     $where .= ") ";
     $query = "SELECT " . $a_id_name . " FROM " . $a_table . " " . $where . "ORDER BY " . $a_field;
     $res = $ilDB->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $ids[] = $row->{$a_id_name};
     }
     return $ids ? $ids : array();
 }
 function _isMember($a_user_id, $a_ref_id, $a_field = '')
 {
     global $rbacreview, $ilObjDataCache, $ilDB;
     $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
     $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"], false);
     $user_roles = $rbacreview->assignedRoles($a_user_id);
     // Used for membership limitations -> check membership by given field
     if ($a_field) {
         include_once './Services/User/classes/class.ilObjUser.php';
         $tmp_user =& ilObjectFactory::getInstanceByObjId($a_user_id);
         switch ($a_field) {
             case 'login':
                 $and = "AND login = '******' ";
                 break;
             case 'email':
                 $and = "AND email = '" . $tmp_user->getEmail() . "' ";
                 break;
             case 'matriculation':
                 $and = "AND matriculation = '" . $tmp_user->getMatriculation() . "' ";
                 break;
             default:
                 $and = "AND usr_id = '" . $a_user_id . "'";
                 break;
         }
         if (!($members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id)))) {
             return false;
         }
         $query = "SELECT * FROM usr_data as ud " . "WHERE usr_id IN (" . implode(",", ilUtil::quoteArray($members)) . ") " . $and;
         $res = $ilDB->query($query);
         return $res->numRows() ? true : false;
     }
     if (!array_intersect($local_roles, $user_roles)) {
         return false;
     }
     return true;
 }
 /**
  *	Delete meta data of a content object (pages, chapters)
  *   @access    public
  *	@param array of child ids
  *	@see _getAllChildIds()
  *	@return boolean
  */
 function _deleteAllChildMetaData($a_ids)
 {
     global $ilBench, $ilDB;
     #$ilBench->start('NestedSet','deleteAllChildMetaData');
     // STEP TWO: DELETE ENTRIES IN xmlnestedset GET ALL tag_fks
     $in = " IN (";
     $in .= implode(",", ilUtil::quoteArray($a_ids));
     $in .= ")";
     $query = "SELECT ns_tag_fk FROM xmlnestedset " . "WHERE ns_book_fk " . $in;
     $res = $ilDB->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $tag_fks[$row->ns_tag_fk] = $row->ns_tag_fk;
     }
     $ilDB->query("DELETE FROM xmlnestedset WHERE ns_book_fk " . $in);
     // FINALLY DELETE
     $in = " IN (";
     $in .= implode(",", ilUtil::quoteArray($tag_fks));
     $in .= ")";
     $ilDB->query("DELETE FROM xmlparam WHERE tag_fk " . $in);
     $ilDB->query("DELETE FROM xmlvalue WHERE tag_fk " . $in);
     $ilDB->query("DELETE FROM xmltags  WHERE tag_pk " . $in);
     #$ilBench->stop('NestedSet','deleteAllChildMetaData');
     return true;
 }